Gui not closing

hey i have wrote out a script for the gui to wait to close but it doesnt can anyone help?
code:

local function onClick()
	local players = game:GetService("Players")
	local player = players.LocalPlayer

	for i = 1, 0, -0.1 do

		script.Parent.Parent.Parent.Music.Volume = i
		wait(0.07)
	end

	script.Parent.Parent.Parent.Music:Stop()
	player.Character.Humanoid.Health = 0

end

script.Parent.MouseButton1Click:Connect(onClick)
script.Parent.PlayButton.MouseButton1Click:Connect(onClick)

delay(0.5)
script.Parent.Parent.Visible = false
1 Like

Switch out delay for wait. I think delay is deprecated?

ill check it out right now thanks

right the gui isnt showing when i join now

Up time the wait before you set visible to false and do you get any errors.

right i have tried 2 scripts they still leave on the gui when the player has clicked it

What gui are you trying to disabled

MenuGui the gui that has everything in it

This will disabled the main gui when you click

local function onClick()

    local players = game:GetService("Players")

    local player = players.LocalPlayer

    for i = 1, 0, -0.1 do

        script.Parent.Parent.Parent.Music.Volume = i

        wait(0.07)

    end

    script.Parent.Parent.Parent.Music:Stop()

    player.Character.Humanoid.Health = 0

    MainGui.Enabled = false

end

script.Parent.MouseButton1Click:Connect(onClick)

script.Parent.PlayButton.MouseButton1Click:Connect(onClick)

is it possible for it to wait 5 seconds then it closes

This will wait 5 seconds after you click the gui.

local function onClick()
	local players = game:GetService("Players")
	local player = players.LocalPlayer

	for i = 1, 0, -0.1 do

		script.Parent.Parent.Parent.Music.Volume = i
		wait(0.07)
	end

	script.Parent.Parent.Parent.Music:Stop()
	player.Character.Humanoid.Health = 0
    coroutine.wrap(function()
        wait(5)
        MainGui.Enabled = false
    end)()
end

script.Parent.MouseButton1Click:Connect(onClick)
script.Parent.PlayButton.MouseButton1Click:Connect(onClick)

thank you ill try it out now :slight_smile:

image should it be parent

local function onClick()
	local players = game:GetService("Players")
	local player = players.LocalPlayer

	for i = 1, 0, -0.1 do

		script.Parent.Parent.Parent.Music.Volume = i
		wait(0.07)
	end

	script.Parent.Parent.Parent.Music:Stop()
	player.Character.Humanoid.Health = 0
        wait(5)
        MainGui.Enabled = false -- Set the MainGui to the parent. you can remove the coroutine not really needed.
end

script.Parent.MouseButton1Click:Connect(onClick)
script.Parent.PlayButton.MouseButton1Click:Connect(onClick)

ok let me give this a shot now

yeah still stays the same its just got the gui up and not closing

Is the gui a Frame or a ScreenGui?

it is a screen gui :smiley: :+1:

Does the onClick function fire when you click the gui?

im unsure how should i check? :thinking: