Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Gui disappears instantly?

Ok so, the gui shows perfectly fine, BUT. After it has shown and the player touched the block again the gui instantly disappears and doesn't wait the 2 seconds again?

Value = game.Workspace.Portals.Blue

function onTouched(part)
	if Value.Value == false then
		local Player = game.Players.LocalPlayer
		local Frame = Player.PlayerGui.Messages.Locked
		Frame.Visible = true
		wait(2)
		Frame.Visible = false
	else
		part.CFrame = CFrame.new(script.Parent.Parent.Parent.BlueR1.Position.x, script.Parent.Parent.Parent.BlueR1.Position.y + 5,  script.Parent.Parent.Parent.BlueR1.Position.z)
	end
end


script.Parent.Touched:connect(onTouched)

EDIT: Sometimes it does wait, sometimes it doesn't?

2 comments

0

When you set Frame.Visible to true, you should also set Value.Value to true. Then, after the two second wait-time, when you set the Frame.Visible to be false, you should set the Value.Value to false as well.

0

But setting Value.Value to true will cause the player to run the part.CFrame, which is not what I want.

1 answer

✓ Accepted answer

You could use a debounce, so that multiple touches without waiting for the full 2 seconds will be ignored:

local debounce = false

script.Parent.Touched:connect(function(hit)
    if not debounce then
        debounce = true
        -- code
        debounce = false
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.