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

What's wrong with this?

Asked by
Zerio920 285 Moderation Voter
10 years ago
local deb = false

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if deb == true then return end
        deb = true
wait()
local a = game.Players:GetPlayerFromCharacter(hit.Parent)
repeat wait() until a:FindFirstChild("PlayerGui")
local b = a.PlayerGui:GetChildren()
for i=1, #b do
if b[i].className == "ScreenGui" then
return end
end
            script.Parent.CanCollide = false
end
    deb = false
end)

It checks to see if the player touching it has any guis inside him. If he doesn't, the brick becomes noncancollide. It works in solo but not in server for some reason.

1 answer

Log in to vote
0
Answered by
2eggnog 981 Moderation Voter
10 years ago

If the gui is present, the function returns before it gets a chance to disable the debounce. After testing the fixed version, it works fine in both server and solo.

local deb = false

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if deb == true then return end
        deb = true
        local a = game.Players:GetPlayerFromCharacter(hit.Parent)
        repeat wait() until a:FindFirstChild("PlayerGui")
        local b = a.PlayerGui:GetChildren()
        for i=1, #b do
            if b[i].className == "ScreenGui" then
            deb = false
            return end
        end
        script.Parent.CanCollide = false
    end
    deb = false
end)
Ad

Answer this question