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

Open / Close Gui Dosent know why i cant use this?

Asked by
DevingDev 346 Moderation Voter
8 years ago

I dont really know why this isnt working why cant i do like this when i clicked on the textbutton then i close the gui but it dosent seem to work. Heres the code

function onClick()
    game.StarterGui.ChooseLevel.Main.Visible = false
end

script.Parent.MouseButton1Click:connect(onClick)

2 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Try making a local script inside the text button and then paste the following code in it:

script.Parent.MouseButton1Click:connect(function()
    local GUI = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ChooseLevel"):WaitForChild("Main")

    if GUI .Visible then
        GUI.Visible = false
        script.Parent.Text = "Open"
    else
        GUI.Visible = true
        script.Parent.Text = "Close"
    end
end)

I even added some extra code so it changes the button text to say "Open" or "Close"!

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

You are supposed to find the GUI in the playerGui, not the StarterGui: Game.Players.LocalPlayer.PlayerGui.ChooseLevel.Main.Visible . I believe you are setting the Gui to not show up when new players join the game.

0
It gives me this error "Localplayer is not a valid member of DataModel" and i want the gui to show up when a new player joins i dont want it to be like open first i want it to be like if i join the server then the gui is there on the start DevingDev 346 — 8y
0
Wait, i should've asked this first before posting my answer... Where do you have the script? Is it a Local script? addictedroblox1414 166 — 8y
0
its in a textbutton, and no its not a local script DevingDev 346 — 8y
0
Is the textbutton on a brick? Or on the players screen? addictedroblox1414 166 — 8y
View all comments (4 more)
0
on the players screen DevingDev 346 — 8y
0
Just a heads up. It's "game.Players.LocalPlayer". Not "game.LocalPlayer" TheHospitalDev 1134 — 8y
0
Oh that's right! Thanks @TheHospitalDev. I just edited my post. addictedroblox1414 166 — 8y
0
Another question, where do you have the textbutton along with the script? Inside Workspace or inside the StarterGUI? If you could provide a picture with how you have it set-up then it would be much easier to help you. This is only if you are absolutely sure you want to have it this way. Otherwise, read ScripterTonys answer up above. Do what he says, and then put the textbutton along with the scrip addictedroblox1414 166 — 8y

Answer this question