Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help displaying Players on a Team on TextLabels?

Let me clarify what I'm trying to so. I have 12 bricks in a model, each with a SurfaceGui and TextLabel. I want to display a single player on each brick with their name on the TextLabel.

Here is my script below. Please do not comment on my scripting methods unless you know what you are talking about, and can provide a more efficient way to write it.

plr = game.Teams.Racing:GetPlayers()

function update()
	local c = script.Parent:GetChildren()
	for i = 1,#c do
		if string.sub(c[i].Name, 1, 5) == "Yield" then
			c[i].SurfaceGui.TextLabel.BackgroundTransparency = 1
			c[i].SurfaceGui.TextLabel.Text = ""
		end
	end
	for i = 1,#plr do
		local item = script.Parent:FindFirstChild("Yield" .. tostring(i)).SurfaceGui.TextLabel
		if (item~=nil) then
			item.BackgroundTransparency = 0
			item.Text = plr[i].Name
		end
	end
end


spawn(function()
	while wait() do
		update()
	end
end)

Many thanks, Salt

1 answer

✓ Accepted answer

You never update your plr value (also concider changing it to local)

What that means is it will always use the same table. Assuming it runs directly, this will always be an empty table. ({}) Simpfully put line 1 into the update function and it could work if you made the rest right.

I Also suggest you switch your while loop to a Changed event.

game.Players.PlayerAdded:Connect(function(plr)
	update()
	plr.Changed:Connect(function(prop)
		if prop == "TeamColor" then
			update()
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function()
	update()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.