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

Why does the gui stay on my screen even though I am not touching the block? plz fix

The script in the part:


while wait(1) do
local part = script.Parent
part.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
plr:WaitForChild("PlayerGui").Quest1.Frame.Visible = true
if part.Touched == false then
("PlayerGui").Quest1.Frame.Visible = false
print(fla)
end
end
end)
end

1 answer

use Part.TouchEnded:Connect(function(hit)

more information here: https://developer.roblox.com/en-us/api-reference/event/BasePart/TouchEnded

(

local part = script.Parent
local debounce = false
part.Touched:Connect(
    function(hit)
        if debounce == false then
            debounce = true
            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
            if plr then
                plr:WaitForChild("PlayerGui").Quest1.Frame.Visible = true
                ("PlayerGui").Quest1.Frame.Visible = true
            end
            wait(3)
            debounce = false
        else
            print("wait.........")
        end
    end
)
part.TouchEnded:Connect(
    function()
        if debounce == false then
            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
            plr:WaitForChild("PlayerGui").Quest1.Frame.Visible = false
        end
    end
)



note: fla is nil and I remove while wait(1) do because it will either break the code or be glitchy

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