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:
1 | player = game.Players.LocalPlayer |
2 |
3 | game.ReplicatedStorage.SupportNumberEvent.OnServerEvent:Connect( function (player) |
4 | game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1 |
5 | player.PlayerGui.MainMenuUS.SupportNumber.Value = player.PlayerGui.MainMenuUS.SupportNumber.Value - 1 |
6 | end ) |
All you need is a 'for... in pairs' loop!
1 | game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1 |
2 | for _, v in pairs (game.Players:GetPlayers()) do |
3 | v.PlayerGui.MainMenuUS.SupportNumber.Value = v.PlayerGui.MainMenuUS.SupportNumber.Value - 1 |
4 | end |
Make sure to put this in an ordinary script, since this action is server-side if I recall correctly.
Cheers.
You cannot get a LocalPlayer from a ServersidedScript!!
1 | game.ReplicatedStorage.SupportNumberEvent.OnServerEvent:Connect( function (player) |
2 | game.StarterGui.MainMenuUS.SupportNumber.Value = game.StarterGui.MainMenuUS.SupportNumber.Value - 1 |
3 | player.PlayerGui.MainMenuUS.SupportNumber.Value = player.PlayerGui.MainMenuUS.SupportNumber.Value - 1 |
4 | 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