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

Gui disappears instantly?

Asked by 8 years ago

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?

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. nilVector 812 — 8y
0
But setting Value.Value to true will cause the player to run the part.CFrame, which is not what I want. KingHolica 10 — 8y

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
Ad

Answer this question