-
What do you want to achieve?
I’m trying to make a spectating system with a list of players to spectate. -
What is the issue?
I am having trouble matching each TextButton’s text to its corresponding player’s name.
My username should appear where you can read “name”:
-
What solutions have you tried so far?
I’ve tried to change the script a little bit, but I can’t seem to find what’s causing this.
This is the actual script, please have in mind that I am a newbie at this and it could just be a dumb error.
for _, plr in game.Players:GetChildren() do
local button = game.ReplicatedStorage.buttonmodel:Clone()
button.Parent = script.Parent
button.Name = plr.Name
button.correspondingplr = plr
button.Text = button.Name
end
game.Players.PlayerAdded:Connect(function(plr)
local button = game.ReplicatedStorage.buttonmodel:Clone()
button.Name = plr.Name
button.correspondingplr = plr
button.Text = button.Name
button.Parent = script.Parent
end)
game.Players.PlayerRemoving:Connect(function(plr)
for _, button in script.Parent:GetChildren() do
if button:IsA("TextButton") then
if button.correspondingplr == plr then
button:Destroy()
end
end
end
end)
Thank you fot the help in advance!