you code has two issues: 1. The event is placed in the function and the function is only called by the event, so the event wont run, as you can see below. 2. functions must be called like this: myFunction(), and the onPlayerAdded() function is not called properly.
local Players = game:GetService("Players")
function onPlayerAdded(p)
if p.Name == "PLAYER_NAME" then
local Item = game.ServerStorage.ITEMNAME:clone()
Item.Parent = p.Backpack
Players.PlayerAdded:connect(onPlayerAdded)
end
end
The following code will function properly:
local Players = game:GetService("Players")
function onPlayerAdded(p)
if p.Name == "PLAYER_NAME" then
local Item = game.ServerStorage.ITEMNAME:clone()
Item.Parent = p.Backpack
end
end
Players.PlayerAdded:connect(onPlayerAdded(p))
or you could do this:
local Players = game:GetService("Players")
Players.PlayerAdded:connect(function(p)
if p.Name == "PLAYER_NAME" then
local Item = game.ServerStorage.ITEMNAME:clone()
Item.Parent = p.Backpack
end
end)