Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I find the player in a global script?

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?

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)

2 comments

0

How can I get the player in a server-side script besides doing the player added?

0

theres no way to do it without doing the player added ok.

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.