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