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

How to change a Players Gui?

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.

1 comment

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.

2 answers

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)

2 comments

0

It worked, thank you so much.

0

No problem(:

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

1 comment

0

Not sure why it still did not work. Just nothing happens after I click the button. Also nothing in the Output.

This discussion is preserved as it was. New answers, comments, and votes are closed.