I have a script that changes the text of a gui when someone clicks a button. I want to make it so when one person clicks on the button, everyone sees the change. How can I do that in a global script?
✓ ANSWER ACCEPTED
How can I find the player in a global script?
2 answers
✓ Accepted answer
You can only get LocalPlayer in a LocalScript
LocalScript:
local Player = game.Players.LocalPlayer
print(Player.Name)
Server-Side:
game.Players.PlayerAdded:connect(function(Player)
print(Player.Name)
end)
Simple really. Using Events you can return a local player without having to use a LocalScript.
gui = game.StarterGui.GuiNameHere -- The GUI
guiButton = gui.TextButton -- The Button
guiText = gui.TextLabel
guiButton.MouseButton1Click:connect(function(player)
guiText.Text = "Hello World! 1337"
end)
Simple as that.
EDIT: Here is a edited version changing the GUI that would be inside a players PlayerGui by using Parameters.
guiButton.MouseButton1Click:connect(function(player)
player.PlayerGui.ScreenGui.guiText.Text = "Hello World! 1337"
end)
2 comments
0
This references the original starter gui though, don't we want to reference the player's playergui?
0
You mentioned you wanted everyone to see the change. Best solution would be to put it in the StarterGui.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
How can I get the player in a server-side script besides doing the player added?
theres no way to do it without doing the player added ok.