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

How to change a Players Gui?

Asked by 9 years ago

So I have a Button that when you click it I want it to change the players Gui from Unemployed to Cashier. It is not working and I can't figure out why. Any help? Here is what I got:


function onClicked(player) game.player.PlayerGui.Job.Jobname.Text = "Cashier" end script.Parent.ClickDetector.mouseClick:connect(OnClicked)

P.S It is not in a local script, just an ordinary one. And this script is inside the Brick that you click.

0
It is not recommended to modify client-sided things from the server. PlayerGui objects are considered client-sided things. If you use RemoteEvents and RemoteFunctions to communicate between the client and server, your games will be much more secure. blocco 185 — 9y

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Little typo on the connection statement;

'...ClickDetector.mouseClick'

also you're identifying the player wrong;

'game.player' --parameter 'player' leads directly to the player value

And lastly, your function name and calling has to match;

'function onClicked(player)', '...:connect(OnClicked)'

Try this;

script.Parent.ClickDetector.MouseClick:connect(function(player)
    player.PlayerGui.Job.Jobname.Text = "Cashier"
end)
0
It worked, thank you so much. CrispyBrix 113 — 9y
0
No problem(: Goulstem 8144 — 9y
Ad
Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago
function onClicked(player) --player is already a variable here, you do not need game. at the beginning of the next line.
    player:WaitForChild("PlayerGui").Job.Jobname.Text = "Cashier" --The wait for child is just making sure PlayerGui exists.
end

script.Parent.ClickDetector.MouseClick:connect(onClicked) --I am not sure if MouseClick is case sensitive, but I modified it anyways.
--And you are calling the wrong function. Lua IS CASE SENSITIVE!
--The script was looking for OnClicked when you only have onClicked
0
Not sure why it still did not work. Just nothing happens after I click the button. Also nothing in the Output. CrispyBrix 113 — 9y

Answer this question