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

My onclicked script isn't working. Why?

Asked by 9 years ago
1function onClicked(playerWhoClicked)
2    game.StarterGui.Magical.ScreenGui.TextLabel.Visible = true
3end
4 
5script.Parent.ClickDetector.MouseClick:connect(onClicked)

The Visible property of the Text Label is set to false.

2 answers

Log in to vote
2
Answered by
Sublimus 992 Moderation Voter
9 years ago

The StarterGui holds the Guis that are handed out to players when they spawn. However, since Guis are independent from player to player, each player contains a PlayerGui within their Player object.

If you want the changes to be visible to a player without them respawning, you must directly edit their PlayerGui.

The ClickDetectors parameter playerWhoClicked holds the Player object of the player who clicked it.

So using this information, this script should work:

1function onClicked(playerWhoClicked)
2 
3    playerWhoClicked.PlayerGui.Magical.ScreenGui.TextLabel.Visible = true
4 
5end
6 
7script.Parent.ClickDetector.MouseClick:connect(onClicked)

Additional Resources:

MouseClick

StarterGui

PlayerGui

Arguments and Parameters

0
Thanks for your help! This worked out perfectly for me. clalexander 40 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

StarterGui
And never again

You want to use playerWhoClicked.PlayerGui instead of StarterGui, as StarterGui only updates when the Player respawns, and changes universally.

1function onClicked(playerWhoClicked)
2     playerWhoClicked.PlayerGui.Magical.ScreenGui.TextLabel.Visible = true
3end
4 
5script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Beat me to the answer. Haha. Sublimus 992 — 9y
0
Of course I did. I explained what they needed to know in a concise but still elegant format. User#6546 35 — 9y

Answer this question