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

How do I make a script that affects everyone's GUI?

Hello, I'm trying to make a script that affects a value inside a GUI for everyone because I'm trying to make a system that only allows classes a certain number of people to be in that class.

Script:

player = game.Players.LocalPlayer

game.ReplicatedStorage.SupportNumberEvent.OnServerEvent:Connect(function(player)
	game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1
	player.PlayerGui.MainMenuUS.SupportNumber.Value = player.PlayerGui.MainMenuUS.SupportNumber.Value - 1
end)

2 answers

✓ Accepted answer

All you need is a 'for... in pairs' loop!

game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1
for _, v in pairs(game.Players:GetPlayers()) do 
	v.PlayerGui.MainMenuUS.SupportNumber.Value = v.PlayerGui.MainMenuUS.SupportNumber.Value - 1
end

Make sure to put this in an ordinary script, since this action is server-side if I recall correctly.

Cheers.

2 comments

1

Thank you! This was very helpful and now I know something new about scripting.

0

No problem! Happy coding!

You cannot get a LocalPlayer from a ServersidedScript!!

game.ReplicatedStorage.SupportNumberEvent.OnServerEvent:Connect(function(player)
    game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1
    player.PlayerGui.MainMenuUS.SupportNumber.Value = player.PlayerGui.MainMenuUS.SupportNumber.Value - 1
end)

Just this chunk will do.

In case that still doesn't work, try using a for in pairs() loop to loop through every single player and change the text on the gui

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