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

Trying to get my GUI to work, have i done this correctly?

Asked by 6 years ago

Iv had help from people to try get this to work but its still failing to work in-game. My old script,

local Button = script.Parent
Frame = script.Parent.Parent.SurvivalMenu

function onClick()
if Frame.Visible == false then
Frame.Visible = true
elseif Frame.Visible == true then
Frame.Visible = false
end
end

Button.MouseButton1Click:connect(onClick)

Worked in studio but not in-game and I was given this script,

ImageButton6.MouseButton1Click:connect(function(onClick)
    local Frame = game.StarterGui.SurvivalMenu.Frame
    local ButtonOpen = game.StarterGui.SurvivalMenu.Open
    local ButtonClose = game.StarterGui.SurvivalMenu.Frame.Close

    ButtonOpen.MouseButton1Click:connect(function(onClick) 
        Frame.Visible = true
    end)
end)

To open the GUI, but its still not wanting to open. I have also got a script to close the GUI but its not wanting to currently work.

Any help would be appreciated, thanks.

0
Your old script should work just fine. Try changing "elseif Frame.Visible == true then" to just "else" at line 7. ax_gold 360 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

Do you know the difference of the StarterGui and the PlayerGui?

StarterGui by ROBLOX WIKI

The StarterGui object is a service object that holds GUIs and LocalScripts. Children of this object get cloned into a Player's PlayerGui when their character spawns. If ResetPlayerGuiOnSpawn is false then the children will only be copied to PlayerGui the first time the player's character spawns.

PlayerGui by ROBLOX WIKI

The PlayerGui object is a container that holds a Player's user GUI. If a ScreenGui is a descendant of a PlayerGui, then any GuiObject inside of the ScreenGui will be drawn to the player's screen. Any LocalScript will run as soon as it is inserted into a PlayerGui. When a player first joins a game, their PlayerGui is automatically inserted into their Player object. When the player's Character spawns for the first time all of the contents of StarterGui are automatically copied into the player's PlayerGui. Note that if CharacterAutoLoads is set to false the character will not spawn and StarterGui contents will not be copied until LoadCharacter is called. If ResetPlayerGuiOnSpawn is set to true then every time the player's character respawns all of the contents of that player's PlayerGui is cleared and replaced with the contents of StarterGui.

So! Now do you understand why ur script not work? The correctly version of ur script is that:

Put this in LocalScript

ImageButton6.MouseButton1Click:Connect(function()
    local Player = game:GetService('Players').LocalPlayer
    local = Player:WaitForChild('PlayerGui')
    local Gui = PlayerGui:WaitForChild('SurvivalMenu')

    local Frame = Gui.Frame
    local ButtonOpen = Gui.Open
    local ButtonClose = Gui.Frame.Close

    ButtonOpen.MouseButton1Click:Connect(function() 
        Frame.Visible = true
    end)
end)

and for this check that:

local Player = game:GetService('Players').LocalPlayer
local PlayerGui = Player:WaitForChild('PlayerGui')
local Gui = PlayerGui:WaitForChild('SurvivalMenu')

local TextButton = Gui.TextButton
local Frame = Gui.Frame

TextButton.MouseButton1Click:Connect(function()
    Frame.Visible = not Frame.Visible
end)

So i have a little difficulty to understand ur script. I hope that I helped you, accept my answer if this working.

1
Sorry, i have dyslexia so i understand things differently, Where does the second script go as i got slightly confused with that part. bubyspp1 5 — 6y
0
In the same place than your first script, in the LocalScript in the PlayerGui NiniBlackJackQc 1562 — 5y
Ad

Answer this question