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

Door won't let all of the players in?

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

✓ Accepted answer
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!

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