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

Why won't my Sword speed up if stat is between # and #?

Asked by 9 years ago
P = game.Players.LocalPlayer

while true do
    wait()
    if P.leaderstats.Wind.Value >= 100 <= 500
        then
        script.Parent.Parent.Character.Humanoid.WalkSpeed = 20
    elseif
        P.leaderstats.Wind.Value >= 501 <= 1000
        then
        script.Parent.Parent.Character.Humanoid.Walkspeed = 30
    elseif
        P.leaderstats.Wind.Value >= 1001 <= 5000
        then
        script.Parent.Parent.Character.Humanoid.Walkspeed = 40
    elseif
        P.leaderstats.Wind.Value >= 5001 <= 25000
        then
        script.Parent.Parent.Character.Humanoid.Walkspeed = 50

    end
end
0
Is this a Script or a LocalScript? Where is this script located in the hierarchy? BlueTaslem 18071 — 9y
0
ReplicatedStorage.WindSword.Script and its a Script. attackonkyojin 135 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

You're conditional syntax is incorrect. What you're trying to do is check if a value is between 2 numbers, but the wording isn't correct. The correct syntax is this: if (Value >= Min and Value <= Max) then. So for your first conditional, I would reword it to this:

if P.leaderstats.Wind.Value >= 100 and P.leaderstats.Wind.Value <= 500 then

Also, it would be much simpler to store the Wind value to a variable, so that way you need to do less typing, like so:

local Wind = P.leaderstats.Wind.Value
if Wind >= 100 and Wind <= 500 then

See how much neater that is?

Here's the full fixed code:

local P = game.Players.LocalPlayer
local Humanoid = script.Parent.Parent.Character.Humanoid

while true do
    local Wind = P.leaderstats.Wind.Value
    if Wind >= 100 and Wind <= 500 then
        Humanoid.WalkSpeed = 20
    elseif Wind >= 501 and Wind <= 1000 then
        Humanoid.Walkspeed = 30
    elseif Wind >= 1001 and Wind <= 5000 then
        Humanoid.Walkspeed = 40
    elseif Wind >= 5001 and Wind <= 25000 then
        Humanoid.Walkspeed = 50
    end
    wait()
end

Hope this helped!

Ad

Answer this question