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

Debounce doesn't work?

Asked by 8 years ago

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)

3 answers

Log in to vote
1
Answered by
drahsid5 250 Moderation Voter
8 years ago

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

Ad
Log in to vote
0
Answered by
joalars2 107
8 years ago

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

0
It is also local to the if statement. drahsid5 250 — 8y
0
Yeah. joalars2 107 — 8y
Log in to vote
-2
Answered by 8 years ago

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.

0
Irrelevant to his question, you should have read more. drahsid5 250 — 8y
0
Sorry. ;/ ShinoKae 0 — 8y

Answer this question