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

Why isn't this working?

Asked by 10 years ago

When I click it, it won't work :/

1function onClick()
2    if game.StarterGui.ScreenGui.Frame.Visible ==false then
3        game.StarterGui.ScreenGui.Frame.Visible = true
4    else
5        game.StarterGui.ScreenGui.Frame.Visible = false
6    end
7end
8script.Parent.MouseButton1Click:connect(onClick)

No ideas anymore help would be... well helpful :b

2 answers

Log in to vote
0
Answered by 10 years ago

Don't use the StarterGui, use this:

1game.Players.LocalPlayer.PlayerGui
Ad
Log in to vote
2
Answered by 10 years ago

Since this is a Gui, you should usually use a LocalScript as it prevents server lag from the Gui, and it is only happening for that Player.

Now, a better way to do this would be to connect the function right away, like so:

1script.Parent.MouseButton1Click:connect(function()
2end)

Doing this can save a line, and a bit of time.

Your next error would be that you are going to the StarterGui instead of the PlayerGui, which can be done as so:

1Player = game.Players.LocalPlayer
2PGui = Player.PlayerGui

Everything else looks fine, good luck!

Answer this question