Badge Door unstable, can't punish correctly

Hi I’m Ryxku and I want to make a Badge Door in server side for my game. I don’t want to use Local Script to prevent from cheaters.
My current script works but will stop working if I try to abuse it and cross it every second.
What can I do for?
It’s a bug that I’d like to keep a bit, in the sense that if the script notices that it’s the same player going back and forth through the door, let him be punished and killed. Hopefully, this will make him stop.

local door = script.Parent
local badgeHolder = door.Parent.BadgeID
local debounce = false

local function find(userId, badgeId)
	local success, result = pcall(function()
		local badgeService = game:GetService("BadgeService")
		return badgeService:UserHasBadgeAsync(userId, badgeId)
	end)

	if success then
		return result
	else
		warn("Error in UserHasBadgeAsync:", result)
		return false
	end
end

local function onTouched(hit)
	if not debounce and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			wait(0.5)
                        local debounce = true
			if find(player.UserId, badgeHolder.Value) then
				door.Transparency = 0.8
				door.CanCollide = false
				wait(0.3)
				door.Transparency = 0.5
				door.CanCollide = true
			else
				hit.Parent.Humanoid.Health = 0
			end
		end
	end
       local debounce = false
end

door.Touched:Connect(onTouched)
2 Likes