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

How can I find the player in a global script?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)
0
How can I get the player in a server-side script besides doing the player added? CardboardRocks 215 — 10y
0
theres no way to do it without doing the player added ok. DragonSkyye 517 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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)
0
This references the original starter gui though, don't we want to reference the player's playergui? CardboardRocks 215 — 10y
0
You mentioned you wanted everyone to see the change. Best solution would be to put it in the StarterGui. RobloxHelper49 55 — 10y

Answer this question