ServerScript won't add the proper WalkSpeed

Right now I am making a ability that will boost the player’s Speed, Damage, and Health. Everything is going fine except the player’s speed, whenever I try to add 8 WalkSpeed to the player’s current WalkSpeed it adds 12.971 WalkSpeed

since this is such an odd thing I couldn’t really find anything to help (However I didn’t search that long either because I was about to go to bed)

and also if anyone does find a solution make sure it adds on to the current WalkSpeed and not sets WalkSpeed

DmgMultiplier.Value = DmgMultiplier.Value + 0.2
hum.WalkSpeed = hum.WalkSpeed + 8
hum.Health = hum.Health + 20

task.wait(20)

DmgMultiplier.Value = DmgMultiplier.Value + 0.2
hum.WalkSpeed = hum.WalkSpeed - 8
2 Likes

What are your variables for all of this?

2 Likes

Well, to fix this, in my opinion, i would replace the current code with this code, to ensure that the character is added, then we wait for the humanoid, this is inside of a ServerScript of course.

-- // Variables < --

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
          local hum = char:WaitForChild("Humanoid")
          DmgMultiplier.Value = DmgMultiplier.Value + 0.2
          hum.WalkSpeed = hum.WalkSpeed + 8
          hum.Health = hum.Health + 20

          task.wait(20)

          DmgMultiplier.Value = DmgMultiplier.Value + 0.2
          hum.WalkSpeed = hum.WalkSpeed - 8
    end)
end)
2 Likes

Problems with changing a player’s walkspeed from a server script are often caused by a local script changing the walkspeed of the player at a different time (the walkspeed will appear to change but the actual value is not replicated to the humanoid on the server). This causes a desync between the server and the client, where the server does not detect the localscript changing the walkspeed of the player, and when the server then updates the walkspeed it will update incorrectly.

2 Likes

Sorry, I Should’ve gone more in-depth, so the code I’ve shown happens from an event fired from a local script when a player presses the number 2 on their keyboard, it already knows the character, it just won’t change the walkspeed properly, whenever I want to make it add 8 it adds 12.971

1 Like

Can I see the local script? Also, do you get any bugs when you press 2?

2 Likes

I just understood what you meant, I was doing some tinkering with other scripts and found the issue

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.