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

Door won't let all of the players in?

Asked by 10 years ago

I made this cafe and there is a door that only allows certain people in, when I went to test it out, it never worked. Here is the code

--Made by Gangnumstylefan

local sp=script.Parent

function onTouched(hit)
h = hit.Parent.Name
if game.Players.LocalPlayer.Name =="gangnumstylefan" or "Khyrax" or "Player1" then
sp.CanCollide = false
wait(3)
sp.CanCollide = true
end end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago
access ={"gangnumstylefan", "Khyrax", "Player1"}

function debounce(func)
    local isRunning = false    -- Create a local debounce variable
    return function(...)       -- Return a new function
        if not isRunning then
            isRunning = true

            func(...)          -- Call it with the original arguments

            isRunning = false
        end
    end
end

script.Parent.Touched:connect(debounce(function(hit)
    if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
        p = game.Players:GetPlayerFromCharacter(hit.Parent)
        for i,v in pairs(access) do
            if p.Name:lower() == v:lower() then
                script.Parent.Transparency = 0.7
                script.Parent.CanCollide = false
                wait(0.5)
                script.Parent.Transparency = 0
                script.Parent.CanCollide = true
            end
        end
    end
end))

~ Thank me by accepting this answer/bumping up my reputation!

Ad

Answer this question