I’m trying to make it so it updates when a new player joins a team.
local teams = #game.Teams[“Players -”]:GetPlayers()
while true do
script.Parent.SurfaceGui.SIGN.Text = teams
end
This is some code I made.
Should I use a remote event instead?
I’m trying to make it so it updates when a new player joins a team.
local teams = #game.Teams[“Players -”]:GetPlayers()
while true do
script.Parent.SurfaceGui.SIGN.Text = teams
end
This is some code I made.
Should I use a remote event instead?
The code you’ve written gets the count of the players on a specific team, then perpetually displays it to a surface GUI. This is not the same as perpetually getting the count of the players on a specific team, then displaying it on a surface GUI. Move your “teams” variable into the loop so it may be included in the update cycle.
Furthermore, your loop contains no yield. Roblox is cooperatively multi-tasked, meaning only one thread of execution exists at a time. Other threads are allowed execution when the currently executing thread pauses or completes. If a thread never gives up its spotlight, vital threads do not get executed, which can cause temporary freezing.
A simple task.wait
will do. This is called busy-waiting, however, and it’s not an optimal solution given the available alternatives. Instead of using your loop, create a function that updates the surface GUI with the current team count. Call it once to initialize the surface GUI, then connect it to Team.PlayerAdded and Team.PlayerRemoving to update the GUI at appropriate times.
Thank you, it works like a charm!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.