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
This should give PLAYER_NAME the ITEMNAME on login, however it doesn't. Yes the ITEMNAME is in the ServerStorage.
on line 9: game.Players.PlayerAdded:connect(onPlayerAdded)
also idk if this is a problem but i think its Clone() and not clone()
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) -- the event even if it occurs will never call the function because it's placed in the function and the function is not called properly as well 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)