Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
itsbboy 17
2 years ago
Edited by JesseSong 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

1
Thank you! This was very helpful and now I know something new about scripting. itsbboy 17 — 2y
0
No problem! Happy coding! satyajit_ray 60 — 2y
Ad
Log in to vote
1
Answered by 2 years ago

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

Answer this question