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

Debounce doesn't work?

I was making a tool for my RPG (Yes a tool - dw it's the only one in the game) and I made a debounce so I can't spam it, but I can still spam it. Help please! The problem starts on line 61

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://334670485"

local rand = math.random(1,6)


local player = game.Players.LocalPlayer

function playAnimation(Animation)
  local animationTrack = script.Parent.Parent.Humanoid:LoadAnimation(Animation)
  animationTrack:Stop()
  wait()
  animationTrack:Play()
end

tool.Handle.BrickColor = BrickColor.new("Black") 
tool.Handle2.BrickColor = BrickColor.new("Really black")

if rand == 1 then
	tool.Type.Value = "GreatLightning"
elseif rand == 2 then
	tool.Type.Value = "GreatPlasma"
elseif rand == 3 then
	tool.Type.Value = "GreatDark"
elseif rand == 4 then
	tool.Type.Value = "GreatMoon"
elseif rand == 5 then
	tool.Type.Value = "GreatTele"
elseif rand == 6 then
	tool.Type.Value = "GreatElemental"
end

if tool.Type.Value == "GreatLightning" then
	tool.Handle.BrickColor = BrickColor.new("Steel blue")
	tool.Handle2.BrickColor = BrickColor.new("Electric blue")
	tool.Handle3.BrickColor = BrickColor.new("Teal")
elseif tool.Type.Value == "GreatPlasma" then
	tool.Handle.BrickColor = BrickColor.new("Alder")
	tool.Handle2.BrickColor = BrickColor.new("Really red")
	tool.Handle3.BrickColor = BrickColor.new("Dark indigo")
elseif tool.Type.Value == "GreatDark" then
	tool.Handle.BrickColor = BrickColor.new("Black")
	tool.Handle2.BrickColor = BrickColor.new("Black")
	tool.Handle3.BrickColor = BrickColor.new("Really black")
elseif tool.Type.Value == "GreatMoon" then
	tool.Handle.BrickColor = BrickColor.new("Pearl")
	tool.Handle2.BrickColor = BrickColor.new("Butter milk")
	tool.Handle3.BrickColor = BrickColor.new("Daisy orange")
elseif tool.Type.Value == "GreatTele" then
	tool.Handle.BrickColor = BrickColor.new("Shamrock")
	tool.Handle2.BrickColor = BrickColor.new("Pastel green")
	tool.Handle3.BrickColor = BrickColor.new("Lime green")
elseif tool.Type.Value == "GreatElemental" then
	tool.Handle.BrickColor = BrickColor.new("Bright blue")
	tool.Handle2.BrickColor = BrickColor.new("Pearl")
	tool.Handle3.BrickColor = BrickColor.new("Electric blue")
end

function redeem()
	local debounce = false
	if debounce == false then
		debounce = true	
		playAnimation(anim)
		wait(5)
			for i = 0, 1, 0.1 do
				tool.Handle.Transparency = i
				wait(0.1)
			end
			for i = 0, 1, 0.1 do
				tool.Handle2.Transparency = i
				wait(0.1)
			end
			for i = 0, 1, 0.1 do
				tool.Handle3.Transparency = i
				wait(0.1)
			end
	  	if tool.Type.Value == "GreatLightning" then
			print("GreatLightning") --temp
			print("player.leaderstat.Sotsune = GreatLightning") --temp
			script.Parent:Remove()
		end
		if tool.Type.Value == "GreatPlasma" then
			print("GreatPlasma") --temp
			print("player.leaderstat.Sotsune = GreatPlasma") --temp
			script.Parent:Remove()
		end
		if tool.Type.Value == "GreatDark" then
			print("GreatDark") --temp
			print("player.leaderstat.Sotsune = GreatDark") --temp
			script.Parent:Remove()
		end
		if tool.Type.Value == "GreatMoon" then
			print("GreatMoon") --temp
			print("player.leaderstat.Sotsune = GreatMoon") --temp
			script.Parent:Remove()
		end
		if tool.Type.Value == "GreatTele" then
			print("GreatTele") --temp
			print("player.leaderstat.Sotsune = GreatTele") --temp
			script.Parent:Remove()
		end
		if tool.Type.Value == "GreatElemental" then
			print("GreatElemental") --temp
			print("player.leaderstat.Sotsune = GreatElemental") --temp
			script.Parent:Remove()
		end
		debounce = false
	end
end

tool.Activated:connect(redeem)

1 comment

3 answers

✓ Accepted answer

You made the debounce local to the if statement, remove it and insert it at line four.

Pretty sure you're setting the debounce to "False" every time you click. Try moving it upwards to the top of the script.

2 comments

0

It is also local to the if statement.

0

Yeah.

Do you mind changing it to this in Line 62:

if debounce == false then
wait(0.1)
debounce = true

Sometimes wait is required, so that scripts can function properly and they'll know when to stop or start,loop.

2 comments

0

Irrelevant to his question, you should have read more.

0

Sorry. ;/

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