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

Im trying to clone buttons which shows a backpack of a player but it's not working?

Asked by 5 years ago

for _,v in pairs(game.Players[target.Parent.Name].Backpack:GetChildren()) do print('a') local clone = game.Players[name].PlayerGui.TCKTGUI.Frame.toolex:Clone() clone.img.TextLabel.Text = v.Name clone.Name = v.Name clone.Parent = game.Players[name].PlayerGui.TCKTGUI.Frame.ScrollingFrame end

what it's trying to do: make clone a textbutton into a scrollingframe which displays the contents of the target player's backpack but it'n not getting past the for_,v loop

https://gyazo.com/808a1dfd5bab1fee804e45fa4863c084

1 answer

Log in to vote
0
Answered by 5 years ago

The reason why your generic for loop is not starting is because you're trying to index the Players Service. You cannot index services, however, you can index a table.

Also, you're trying to index something using what I'm assuming is the player's name. You cannot index a table of objects using a name, and you cannot index this table of objects using the player's model. So instead you will have to use GetPlayerFromCharacter(). If you use that, you don't really need to use GetPlayers(), but I'll show it both ways just in case.

Instead of doing this:

for _,v in pairs(game.Players[target.Parent.Name].Backpack:GetChildren()) do

You can do:

for _,v in pairs(game.Players:GetPlayers()[game.Players:GetPlayerFromCharacter(target.Parent)].Backpack:GetChildren()) do

All I did was use the GetPlayers() method on the Players Service which returned a table of all the players who are currently in the server. Next, I indexed that table using the actual player object and then got the children of the backpack.

To be honest, you don't really need to do all that. Instead, you can do:

for _,v in pairs(game.Players:GetPlayerFromCharacter(target.Parent).Backpack:GetChildren()) do

If you have any questions just comment below, and please mark this answer as accepted if it worked.

Ad

Answer this question