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

My onclicked script isn't working. Why?

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

✓ Accepted answer

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

1 comment

0

Thanks for your help! This worked out perfectly for me.

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)

2 comments

0

Beat me to the answer. Haha.

0

Of course I did. I explained what they needed to know in a concise but still elegant format.

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