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

Why my BoolValue changer on my script is not working?

Asked by 6 years ago

Why the IsAttacking BoolValue's Value doesn't change?

Tool = script.Parent
Damage = script.Parent.Settings.Damage
local ButtonPressed = false
Attacking = script.Parent.Scripts.IsAttacking

Tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()
----------------------------------------------------------------------  
        script.Parent.DamagePart.Touched:connect(function(hit)
            if not ButtonPressed then
                --is it not pressed?
                ButtonPressed = true
                Attacking.Value = true -- here
                --
                --
                if hit.Parent then
                local human = hit.Parent
                hum = human:FindFirstChild("Humanoid")
                if hum then
                    hum.Health = hum.Health - script.Parent.Settings.Damage.Value
                else
                    print("Humanoid Not Found")
                end
                wait(1)
                end
                --
                Attacking.Value = false -- here
                ButtonPressed = false
            end
        end)
---------------------------------------------------------------------
    end)
end)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

That's because your Bool Value immediately sets to True whenever the Touched event fires, so it never changes.

Perhaps add a wait() before setting IsAttacking to false

Ad
Log in to vote
0
Answered by 6 years ago

Use a direct boolean instead of one located in the Workspace, like:

bool = true

Answer this question