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)
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.
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