Humanoid.Walkspeed Wont Change

Hello i have a sprinting script that worked completely fine and ive looked up many solved posts already that did not help my problem at all

the issue lies in that whatever i do the humanoid.walkspeed doesnt change at all no matter what i do

also ive tried printing as much information as possible and everything was as it should, the parent of the humanoid was the right player and so on

This is my sprinting script:

local UIS = game:GetService("UserInputService")
local sprinting = script.SprintingState
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local stamina = script.Parent.StaminaHandler.Stamina
local cooldown = script.Cooldown


cooldown = false

UIS.InputBegan:Connect(function(input, GPE)

	if input.KeyCode == Enum.KeyCode.LeftShift then	

		sprinting.Value = true
		print("started running")
		while true do
			if stamina.Value > 0 and sprinting.Value == true and cooldown == false then	

				humanoid.WalkSpeed = 24
				print("speed change succesful")
				
			else

				humanoid.WalkSpeed = 16
				sprinting.Value = false
				print("deactivated sprinting")
				break

			end
			task.wait(0.1)
		end
	end

end)

UIS.InputEnded:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.LeftShift then

		if cooldown == false then
			
			print("cooldown initiated")
			
			cooldown = true
			humanoid.WalkSpeed = 16
			sprinting.Value = false
			task.wait(1.5)
			cooldown = false
			print("cooldown procedure complete")

		end

	end

end)


if youre asking why i got so many bools and values outside of the script it is because i need a gui to read thoose from a different script wich works completely fine and to note that the entire script works fine exept the walkspeed just wont change

and the scripts are located in starterplayerscripts

and when i was printing to see if the value of the .walkspeed changes it normaly printed out to what it should have been set to but the player wasnt moving faster

Is this a local script? That might be the reason why, and if it’s not, it is still more vulnerable to exploits.

this must be in a server script, the player asks the server to Sprint,
then the Server change the walkspeed of the humanoid directly

if you change on a local script, the server walkspeed is different from local script
visually you will see X value, but it will overwrite over and over again, because The server is the priority, not the client, that’s why if you send false information to the server to get high walkspeed (50) the server will adjust

There doesn’t seem to be any errors in the code you provided, so the issue is likely due to interreference from a different script.

I can see you are using a LocalScript to adjust these values, would you by any chance also be setting the WalkSpeed of players from a different script?

Changing the WalkSpeed from a LocalScript will cause the player to move faster, however the server won’t recognize the change of the WalkSpeed, and as such, any update of the WalkSpeed done on the server will immediately reset the player’s speed to whatever the server thinks it should be.

i have looked for any possible scripts that could overwrite it and there doesnt seem any and since you arent the only one saying that it should be a server script im gonna try that and check this as the solution if it works (by server script i mean that the part where it changes speed should be server sided)

You should ideally do all this on the server.

You can only detect user input on the client, so ideally you would do just that.
Detect input on the client, then fire an event letting the server know that the player is trying to run. It is far preferable that you also handle stamina and the like on the server, to prevent your game from being vulnerable to exploits.

Well would you look at that it actualy does work, then thank you very much and everyone else who suggested this. I would never think that this would be the problem since the sprint worked completely fine like 2-3 weeks ago.

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