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

If statement passing even though conditions not met?

Asked by 2 years ago

This code is supposed to check a Value in startercharacter, and if the value is > 0 then it will play an animation and change player properties. It works fine when you first spawn in; the code will not run unless the value is increased. The minute you increase the value (via picking up an item in the world) is where the problem starts. The value actually starts to go into the negative, and the second 'if' statement never intervenes. It also ignores the cooldown put in place to prevent spamming. Why is this happening?

local humanoid = script.Parent:FindFirstChild("Humanoid")
local boosts = humanoid.Parent.Boosts

local casing = humanoid.Parent.animSyringe.Casing
local plunger = humanoid.Parent.animSyringe.Plunger
local needle = humanoid.Parent.animSyringe.Needle
local serum = humanoid.Parent.animSyringe.Serum

local player = game.Players.LocalPlayer

local canBoost = false
local coolDown = true
local keyBind = "g"
local mouse = player:GetMouse()

mouse.KeyDown:Connect(function(key)

    if key == keyBind then

        if boosts.Value > 0 and coolDown == true then

            canBoost = true

        else

            canBoost = false

        end

        if canBoost == true then 

            casing.Transparency = 0
            plunger.Transparency = 0
            needle.Transparency = 0
            serum.Transparency = 0
            serum.BrickColor = BrickColor.new("New Yeller")

            local animation = humanoid:LoadAnimation(script.Animation)
            animation:Play()

            wait(animation.Length)

            casing.Transparency = 1
            plunger.Transparency = 1
            needle.Transparency = 1
            serum.Transparency = 1
            serum.BrickColor = BrickColor.new("White")

            humanoid.WalkSpeed = 20

            boosts.Value = boosts.Value - 1

            wait(30)

            humanoid.WalkSpeed = 16         

            coolDown = false
            wait(60)
            coolDown = true

        end

    end


end)


0
Make an if statement where it checks if its not 0 then it decrease 1 if its not acediamondn123 147 — 2y

Answer this question