How to change the player's walkspeed through a script?

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Character)
		
		local Humanoid = Character:WaitForChild("Humanoid")
		
		function SpinnerWalkSpeed()
			Humanoid.WalkSpeed = 0
			if Humanoid.UseJumpPower == true then
				Humanoid.JumpPower = 80
			else
				Humanoid.JumpHeight = 25
			end
			print("SpinnerSpeed")
		end
		
		function DefaultWalkSpeed()
			Humanoid.WalkSpeed = 16
			if Humanoid.UseJumpPower == true then
				Humanoid.JumpPower = 50
			else
				Humanoid.JumpHeight = 7.2
			end
			print("DefaultSpeed")
		end
		
		--What is happening here?
		SpinnerWalkSpeed()
		DefaultWalkSpeed()
		
	end)
end)

Is this in Server Script service?

Where are you putting this script in? I tried this script on ServerScriptStorage and it works on my end. This was added onto a separate script by itself btw.

It’s a normal script in ServerScriptService.

Did you try out my script? SubToSte left out the players service which can back fire sometimes

I also tried this, It’s not working either…

Here’s the full script.

REMOVED TO PREVENT CODE BEING STOLEN

Please ignore my messy scripting.

Can you send a picture of this script in the sidebar? of the game settings/ Game tab/ Explorer
Because why are you calling server Script service in a server script?

image


is this line in use?

if you’re doing this after the players’ character is added it won’t work…
Please just make a loop that loops through all players in-game, and changes their walk speed.

You going to have to send a client a signal on some kind of event to change their WalkSpeed or even JumpPower.

For some weird reason, you could only change the humanoid WalkSpeed on local scripts only. The server doesn’t do anything.

No, I was just experimenting. Here’s the script that goes with that. (if it wasn’t commented out)

local rep = game:GetService("ReplicatedStorage")
local SpinnerWalkSpeed = rep.WalkSpeedEvents:WaitForChild("SpinnerWalkSpeer")
local DefWalkSpeed = rep.WalkSpeedEvents:WaitForChild("DefWalkSpeed")

SpinnerWalkSpeed.OnClientEvent:Connect(function()
	local player = game.Players.LocalPlayer
	local char = player.CharacterAdded:wait()
	local h = char.Humanoid

	h.WalkSpeed = 0
	h.JumpPower = 80
end)

DefWalkSpeed.OnClientEvent:Connect(function()
	local player = game.Players.LocalPlayer
	local char = player.CharacterAdded:wait()
	local h = char.Humanoid

	h.WalkSpeed = 16
	h.JumpPower = 50
end)

This is false, I have done it just now. It works perfectly fine, this only applies if the characters you are changing is already getting edited by another script

Weird, there was another post a long time ago that was saying to do this in local script. I assumed that roblox’s newest update has fixed that issue. As it wasn’t working for me on Server scripts.

1 Like

Also, I’m using jump power:
image

Did you read what I said 6 posts up?, also I accounted for that, in mine. But what you’re trying to do needs something else, Also why do you need the same line in the server script if you not even going to use it?

Apparently, in line where you try to declare a SpinnerWalkSpeed() was probably a mistake.

Its either you had a function the same name as the event “SpinnerWalkSpeed” or you were trying to send the signal onto the event but in a incorrect way.

I found this in your main script.

Yes I did see what you said, I also tried this and it didn’t work.

Is the second sentence for MineCrablox?.
Because i never posted code 6 post up

Also, I didn’t see any functions inside the Main Script nor was I alerted that the script was changed, as I noticed that the variables were commented and no sight of functions the same as you tried to declare it. Did you get an error of some kind related to “Attempt to call nil”?

I was referring to this. If that’s what you’re asking