Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Putting an item into someone's backpack?

Asked by 9 years ago

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
0
If Perci's answer doesn't work, make sure to put the whole script. Shawnyg 4330 — 9y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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. ]]--
0
yeah but that is exactly what I want, to be in someone,s backpack by his name brokenrares 48 — 9y
Ad

Answer this question