I want to put an item to someone's backpack everytime they come ingame I got a local script inside a HopperBin where the code is.At the end I've put this but didn't work..Any suggestions?
n.Parent = game.Players.PLAYERNAME.Backpack -- n is the HopperBin
In Lua, the dot (.
) searches for an object or property by name.
This means that unless someone has the username "PLAYERNAME", your code won't work.
Since LocalScripts run on the client (that is, the Player's computer), we can use the LocalPlayer
property of the Players service to access player that the script is running on.
n.Parent = game.Players.LocalPlayer.Backpack --[[ There does not have to be a player named 'LocalPlayer' because we are looking for a property, not a child, and that property name is valid. ]]--