Humanoid walkspeed changing in script but not in-game

So… This has me stumped.

I have a script that changes the players walkspeed, AND IT WORKS, the first time I change the stuntime value, it changes the players speed to 4, and it works.

The thing is, the second time I do it, it does not change the walkspeed. When I print the players walkspeed the second time, it says that it’s 4, but it’s literally 15 in the humanoid

FIRST TIME

SECOND TIME

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		wait(3)
		local Debounce = false
		local PlayerFolder = game.ReplicatedStorage.PlayerFolders:FindFirstChild(Player.Name)
		while true do
			wait(.1)
			if PlayerFolder:FindFirstChild("StunTime") then
				if PlayerFolder.StunTime.Value > 0 then
					Debounce = true
					PlayerFolder.StunTime.Value -= .1
					
					if Character.Humanoid.WalkSpeed >= 4 then
						print(Character.Humanoid.WalkSpeed)
						Character.Humanoid.WalkSpeed = 4
					end
				end
			end
		end
	end)
end)
1 Like

On the second time, did you by any chance edit the property from the browser? If you have done it from the client, the changes will not be applied in the property on the server.

No, I change the stuntime value in the server always. Everything is done on the server.

It looks like the issue is that you are not setting the WalkSpeed back to its original value after the StunTime has been reduced to 0. You need to add an if statement that checks if StunTime is 0, and if it is, set the WalkSpeed back to its original value.

if PlayerFolder.StunTime.Value == 0 then
Character.Humanoid.WalkSpeed = 15
end

It already does this using a different script, but that other script does not interfere with the movement speed at all if the stuntime value is above 0. If it did, it would not print the walkspeed print(4)x100, it would be an alternating thing like print(4) print(15) print(4) print(15)