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

How to solve an impossible WalkSpeed error?

Asked by 4 years ago
--onlineone

--Varaibles
char = script.Parent;
hum = char:WaitForChild("Humanoid");

UIS = game:GetService("UserInputService");
RS = game:GetService("ReplicatedStorage");
Remote = RS:WaitForChild("Remote");
UpdateWalkSpeed = Remote:WaitForChild("UpdateWalkSpeed");

speeds = {}
numSpeeds = 0;
callRestart = false;

--Functions
function Speed()print("1")
    numSpeeds = numSpeeds + 1;

    local function Restart() print(2)
        for i, speed in pairs(speeds)do print(3)
            if(numSpeeds > 1)then print("call restart")
                callRestart = true;
                numSpeeds = numSpeeds - 1;

                break;
            end

            if(callRestart == true)then print("restarting")
                callRestart = false;

                if(i > 1)then
                    UpdateWalkSpeed:FireServer(hum.WalkSpeed / speeds[i - 1]);----WON'T PUT THIS VALUE IN NO MATTER WHEN
                    print(hum.WalkSpeed)print("/")print(speeds[i-1])print(hum.WalkSpeed / speeds[i - 1])
                end
                print("WALKSPEED:" .. hum.WalkSpeed)

                Restart();

                break;
            end

            if(i > 1)then
                UpdateWalkSpeed:FireServer((hum.WalkSpeed / speeds[i - 1]) * speeds[i]);
                print(hum.WalkSpeed / speeds[i - 1])print("*")print(speeds[i])print((hum.WalkSpeed / speeds[i - 1]) * speeds[i])
            else
                UpdateWalkSpeed:FireServer(hum.WalkSpeed * speeds[i]);
                print(hum.WalkSpeed)print("*")print(speeds[i])print(hum.WalkSpeed * speeds[i])
            end

            wait(0.05 * i);

            if(i == #speeds)then
                numSpeeds = numSpeeds - 1;
            end
        end
    end

    Restart();
end

UIS.InputBegan:Connect(function(input)
    if(input.KeyCode == Enum.KeyCode.LeftShift and
        hum.WalkSpeed ~= 0)then print("firing")
        Speed();
    end
end)

--Body
for i = 1, 4 do
    table.insert(speeds, i, 1 + (0.35 / i));
end

table.insert(speeds, 5, 1);

The line that says, WON'T PUT THIS VALUE IN NO MATTER WHEN, is the line with the error. The code seemingly updates the player walkspeed, identical to every other time the script does it. However, the feedback shows the following:

restarting 18.800001144409 / 1.175 16.000000973965 WALKSPEED:18.800001144409

The code understands to turn the walkspeed back to 16. It does so, but then, the very next second, it turns back to 18.8. I've tried adding waits everywhere, putting the UpdateWalkSpeed:FireServer in a separate function and calling it from far away, moving it. But no matter how I divide or where I move that line of code ``UpdateWalkSpeed:FireServer(hum.WalkSpeed / speeds[i - 1]); It doesn't change its flawed result. Please, I've been up for the last 3 hours (it's 2:41 am currently) pondering what the possible source of this error could be. I would appreciate it more than anything if someone else knows the solution. Thanks!! :)

0
this is not java, this is lua. this ; is not being used like that in lua Gameplayer365247v2 1055 — 4y
0
@Gameplayer36547v2, Lua supports putting semi-colons after lines in your code, just certain lines can't have it. It doesn't affect the outcome of the code though. RotatedAxis 13 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
--onlineone

--Varaibles
char = script.Parent
hum = char:WaitForChild("Humanoid")

UIS = game:GetService("UserInputService")
RS = game:GetService("ReplicatedStorage")
Remote = RS:WaitForChild("Remote")
UpdateWalkSpeed = Remote:WaitForChild("UpdateWalkSpeed")

speeds = {}
numSpeeds = 0
callRestart = false

--Functions
function Speed()print("1")
    numSpeeds = numSpeeds + 1

    local function Restart() print(2)
        for i, speed in pairs(speeds)do print(3)
            if(numSpeeds > 1)then print("call restart")
                callRestart = true
                numSpeeds = numSpeeds - 1

                break
            end

            if(callRestart == true)then print("restarting")
                callRestart = false

                if(i > 1)then
                    UpdateWalkSpeed:FireServer(hum.WalkSpeed / speeds[i - 1])----WON'T PUT THIS VALUE IN NO MATTER WHEN
                    print(hum.WalkSpeed)print("/")print(speeds[i-1])print(hum.WalkSpeed / speeds[i - 1])
                end
                print("WALKSPEED:" .. hum.WalkSpeed)

                Restart()

                break
            end

            if(i > 1)then
                UpdateWalkSpeed:FireServer((hum.WalkSpeed / speeds[i - 1]) * speeds[i])
                print(hum.WalkSpeed / speeds[i - 1])print("*")print(speeds[i])print((hum.WalkSpeed / speeds[i - 1]) * speeds[i])
            else
                UpdateWalkSpeed:FireServer(hum.WalkSpeed * speeds[i])
                print(hum.WalkSpeed)print("*")print(speeds[i])print(hum.WalkSpeed * speeds[i])
            end

            wait(0.05 * i)

            if(i == #speeds)then
                numSpeeds = numSpeeds - 1
            end
        end
    end

    Restart()
end

UIS.InputBegan:Connect(function(input)
    if(input.KeyCode == Enum.KeyCode.LeftShift and
        hum.WalkSpeed ~= 0)then print("firing")
        Speed()
    end
end)

--Body
for i = 1, 4 do
    table.insert(speeds, i, 1 + (0.35 / i))
end

table.insert(speeds, 5, 1)

i think i changed your code from kinda java i guess to lua so this should work, just removed all the ;

Ad

Answer this question