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

This start GUI won't work?

Asked by
Vid_eo 126
8 years ago

I'm making a start GUI for someones game, but for some reason, the play button won't even act like a TextButton, and the GUI won't disappear when I click on it. Here's the script.

local player = script.Parent.Parent
local gui = script.Parent
local sound = Instance.new("Sound",gui)
sound.SoundId = "http://www.roblox.com/asset/?id=221235033"
sound.Pitch = 1
sound.Volume = 0.7
local frame = gui.Frame
Play = script.Parent.Frame.Play
sound:play()

function OpenCloseGui()
    gui:remove()
end

Play.MouseButton1Down:connect(OpenCloseGui)


Thanks! -club101coolguy

3 answers

Log in to vote
-1
Answered by 8 years ago
local player = script.Parent.Parent
local gui = script.Parent
local sound = Instance.new("Sound", gui)
sound.SoundId = "http://www.roblox.com/asset/?id=221235033"
sound.Pitch = 1
sound.Volume = 0.7
local frame = gui.Frame
Play = script.Parent.Frame.Play
sound:play()

function OpenCloseGui()
    gui:Destroy () -- You did gui:remove() which is not right that is why it was not working.
end

Play.MouseButton1Down:connect(OpenCloseGui)

Hope this works. This should be working. :l i tried it or stuff thing else is wrong like your names of your gui.

0
It doesn't :( Whenever I click, the button doesn't change the slightest bit. Vid_eo 126 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Any output? There is only one problem I can see.

local player = script.Parent.Parent.Parent -- I think this pointed to PlayerGui rather than Player. I've added an extra parent. (if script.Parent is the GUI, then script.Parent.Parent is the PlayerGui)
local gui = script.Parent
local sound = Instance.new("Sound",gui)
sound.SoundId = "http://www.roblox.com/asset/?id=221235033"
sound.Pitch = 1
sound.Volume = 0.7
local frame = gui.Frame
Play = script.Parent.Frame.Play 
sound:play()

function OpenCloseGui()
    gui:Destroy() -- use :Destroy()
end

Play.MouseButton1Down:connect(OpenCloseGui)


Log in to vote
-1
Answered by
woodengop 1134 Moderation Voter
8 years ago

Miswritten Hierarchy and Common Errors:

One of the worst things to experince while programming is miswritting your hierarchy, Be-sure to always double check your hierarchy.


Corrections:

In your script you declared your player variable to script.Parent.Parent and the variable gui is script.Parent, So Obviously you are declaring the player variable to PlayerGui.

local player = game.Players.LocalPlayer
local gui = script.Parent
local sound = Instance.new("Sound",gui)
sound.SoundId = "http://www.roblox.com/asset/?id=221235033"
sound.Pitch = 1
sound.Volume = 0.7
local frame = gui.Frame
Play = script.Parent.Frame.Play
sound:play()

function OpenCloseGui()
    gui:Destroy() 
end

Play.MouseButton1Down:connect(OpenCloseGui)

Additional Definitions:

Many roblox programmers recommend the Destroy method if you are planing to totally dispatch the object and never have it return back to it's previous parent. Also Using script.Parent.Parent.Parent -- etc in a defined variable can cause Confusion and Give you bad programming Habits.

Answer this question