Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allinthenameofgod/4744942c466b25cdcaf14606b89b3ca3 to your computer and use it in GitHub Desktop.
Save allinthenameofgod/4744942c466b25cdcaf14606b89b3ca3 to your computer and use it in GitHub Desktop.
-- Server Script (ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local giveItemEvent = ReplicatedStorage:FindFirstChild("GiveItemEvent")
if not giveItemEvent then
giveItemEvent = Instance.new("RemoteEvent")
giveItemEvent.Name = "GiveItemEvent"
giveItemEvent.Parent = ReplicatedStorage
end
local itemsToGive = { "Sword", "Jetpack" }
local targetUsername = "Bk201XA"
giveItemEvent.OnServerEvent:Connect(function(executingPlayer, targetPlayerName)
if targetPlayerName ~= targetUsername then return end
local targetPlayer = Players:FindFirstChild(targetPlayerName)
if not targetPlayer then return end
local backpack = targetPlayer:FindFirstChild("Backpack")
if not backpack then return end
for _, itemName in pairs(itemsToGive) do
local item = ServerStorage:FindFirstChild(itemName)
if item and item:IsA("Tool") then
item:Clone().Parent = backpack
end
end
print("Items given to " .. targetPlayerName .. " by " .. executingPlayer.Name)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment