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 8 years ago
function onClicked(playerWhoClicked)
    game.StarterGui.Magical.ScreenGui.TextLabel.Visible = true
end

script.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
8 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:

function onClicked(playerWhoClicked)

    playerWhoClicked.PlayerGui.Magical.ScreenGui.TextLabel.Visible = true

end

script.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 — 8y
Ad
Log in to vote
2
Answered by 8 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.

function onClicked(playerWhoClicked)
     playerWhoClicked.PlayerGui.Magical.ScreenGui.TextLabel.Visible = true
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Beat me to the answer. Haha. Sublimus 992 — 8y
0
Of course I did. I explained what they needed to know in a concise but still elegant format. User#6546 35 — 8y

Answer this question