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 10 years ago
01P = game.Players.LocalPlayer
02 
03while true do
04    wait()
05    if P.leaderstats.Wind.Value >= 100 <= 500
06        then
07        script.Parent.Parent.Character.Humanoid.WalkSpeed = 20
08    elseif
09        P.leaderstats.Wind.Value >= 501 <= 1000
10        then
11        script.Parent.Parent.Character.Humanoid.Walkspeed = 30
12    elseif
13        P.leaderstats.Wind.Value >= 1001 <= 5000
14        then
15        script.Parent.Parent.Character.Humanoid.Walkspeed = 40
View all 22 lines...
0
Is this a Script or a LocalScript? Where is this script located in the hierarchy? BlueTaslem 18071 — 10y
0
ReplicatedStorage.WindSword.Script and its a Script. attackonkyojin 135 — 10y

1 answer

Log in to vote
1
Answered by 10 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:

1if 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:

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

See how much neater that is?

Here's the full fixed code:

01local P = game.Players.LocalPlayer
02local Humanoid = script.Parent.Parent.Character.Humanoid
03 
04while true do
05    local Wind = P.leaderstats.Wind.Value
06    if Wind >= 100 and Wind <= 500 then
07        Humanoid.WalkSpeed = 20
08    elseif Wind >= 501 and Wind <= 1000 then
09        Humanoid.Walkspeed = 30
10    elseif Wind >= 1001 and Wind <= 5000 then
11        Humanoid.Walkspeed = 40
12    elseif Wind >= 5001 and Wind <= 25000 then
13        Humanoid.Walkspeed = 50
14    end
15    wait()
16end

Hope this helped!

Ad

Answer this question