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

Why is my debounce not working? I've tried this twice, and it's still not working?

I watched two videos about debouncing, and both times it didn't work. I would still touch the part and it would give me 2-3 to sometimes 7 wins. I don't know why this is going wrong. Can somebody help me and explain what I'm doing wrong or if debouncing has broke?

local WinPart = script.Parent

WinPart.Touched:Connect(function(hit)	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if player then
		
			
			local leaderstats = player:FindFirstChild("leaderstats")
			local Debounce = false
		
			if leaderstats then
			
				if not Debounce then
			
					Debounce = true
					local Location = game.Workspace.TeleportLocation
					
					player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
					hit.Parent.HumanoidRootPart.CFrame = CFrame.new(Location.Position)
					
					wait(1)
					Debounce = false
				end
			end
	end
end)

1 answer

--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local WinPart = script.Parent

local WinLocation = workspace.TeleportLocation


local Debounce = false



--###----------[[FUNCTIONS]]----------###--
local function OnTouched(CharacterBodyPart)
	if (Debounce) then return end
	---------------
	local Character = CharacterBodyPart.Parent
	if (Character) then
		---------------
		local Player = Players:GetPlayerFromCharacter(Character)
		if (Player) then
			---------------
			Debounce = true
			---------------
			Player.leaderstats.Wins.Value += 1
			---------------
			Character:SetPrimaryPartCFrame(WinLocation.CFrame)
			---------------
			wait(1)
			---------------
			Debounce = false
		end
	end
end



--###----------[[SETUP]]----------###--
WinPart.Touched:Connect(OnTouch)

2 comments

0

Nah, I'm good..

0

oh i didnt see this feahren

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