#Button staying activated after death

2 messages · Page 1 of 1 (latest)

timber onyx
#

local function setupHoldBridge(holdBridge)
local debounce = false
local touchCount = 0
local button = holdBridge.Button

    local function activateDoors()
            for _, door in pairs(holdBridge:GetChildren()) do
                    if door.Name == "Door" then
                            door.Transparency = 0
                            door.CanCollide = true
                    end
            end
            button.Material = Enum.Material.Neon
    end
#

local function deactivateDoors()
for _, door in pairs(holdBridge:GetChildren()) do
if door.Name == "Door" then
door.Transparency = 0.6
door.CanCollide = false
end
end
button.Material = Enum.Material.Plastic
end

    button.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") then
                    touchCount = touchCount + 1
                    if touchCount == 1 and not debounce then
                            debounce = true
                            activateDoors()
                            debounce = false
                    end
            end
    end)

    button.TouchEnded:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") then
                    touchCount = touchCount - 1
                    if touchCount <= 0 then
                            touchCount = 0
                            if not debounce then
                                    debounce = true
                                    deactivateDoors()
                                    debounce = false
                            end
                    end
            end
    end)

end

for _, holdBridge in pairs(game.Workspace:GetChildren()) do
if holdBridge.Name == "HoldBridge" then
setupHoldBridge(holdBridge)
end
end