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

Why isn't WalkSpeed changing?

Asked by 1 year ago
Edited 1 year ago

Hello Developers,

I would be very grateful if you could help me with my most recent issue.

Basically, (in the code I have included), I fire a remoteEvent to the client, then change walkspeed, and then print a debug statement.

Both the print statements either side of the walkspeed line output correctly with no other errors in either the console in-game or output window in Roblox Studio.

I would be incredibly grateful if anyone could help me with this.

local slowInformBoostEvent = boostFolder:WaitForChild("SlowInform")

for index, player in pairs(game.Players:GetPlayers()) do
    if player.Status.Value == true then
        if player.Alive.Value == true then
            if player.Murderer.Value == false then
                slowInformBoostEvent:FireClient(player)
                player.Character.Humanoid.WalkSpeed = 4
                print("WalkSpeed should have changed!")
            end
        end
    end
end

Thanks,

Anthony

EDIT: Apologies, I've forgot to add some extra context which I imagine would be useful. This code snippet is inside of a function called executeSlowBoost(), so Players should indeed me in the game (sorry - my fault for not specifying). I have even printed the name of each player who's humanoid walkspeed I am changing (to verify I am indeed getting the correct players as expected). In case it matters, I'm using a server script.

I am really confused because I don't understand how this not working.

Side Note: When I join the game and try to run a command from the server console log:

workspace.[TESTPLAYERNAME].Humanoid.WalkSpeed = 4

This also doesn't produce any errors, HOWEVER it too does not work.

0
Check your game for scripts changing the walkspeed, something is changing it back. Leamir 3138 — 1y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
1 year ago

Hello, Anthony!

The only thing I see with your script is that it is being run as soon as the script is loaded, when there are no players in the game. There are various ways to fix it, and it varies from case to case the best one.

  • Add a wait. If you want to change the walkspeed after some time has passed, adding a wait before the for loop will work. Note that it will only happen once, and if no player is in the game, noone will be affected.

  • Put it inside a loop. Putting it inside a loop will make it run lots of times, just don't forget the wait

It would be nice to have some more context on what this is exactly for.

Re-reading your question, it seems like the code is running when there are players in game, as you said the print is being output to console, however I don't see any errors anywhere else other than what I mentioned. Something that could be happening is the walk speed being changed/reverted by some other script.


If this answers your question, please mark it as the Accepted answer.

0
Hi Leamir! KarateKid147 4 — 1y
0
Apologies, I've forgot to add some extra context which I imagine would be useful. This code snippet is inside of a function called executeSlowBoost(), so Players should indeed me in the game (sorry - my fault for not specifying). I have even printed the name of each player who's humanoid walkspeed I am changing but this still doesn't seem to work. In case it matters, I'm using a server script. KarateKid147 4 — 1y
0
Please see the edits I made to the question. Thanks for your help :) KarateKid147 4 — 1y
0
Thank you so much. You were right, I had a stupid local script randomly changing walkspeed for some reason. Would never have thought of this! Once again, thanks so much! :-) KarateKid147 4 — 1y
Ad

Answer this question