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

I’m trying to make a script that changes the player’s WalkSpeed through a script when a round starts. (Not a localscript)

I’ve tried many different methods but none have worked.

Current method I’m trying:

local function SpinnerWalkSpeed(plr)
	local humanoid = plr.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 80
	end
end

local function DefaultWalkSpeed(plr)
	local humanoid = plr.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
end

All help is appreciated!

3 Likes

Characters aren’t ancestors of their Player instances. However, Player instances do have a Character property which refers to their character model, so you’ll want to do this to define the humanoid instead:

local humanoid = plr.Character and plr.Character:FindFirstChildOfClass("Humanoid")

I get this error:
ServerScriptService.RoundScript:24: attempt to index nil with 'Character'

1 Like

Did you define the player object? Also, it’s a Player Instance, right?

Also, where is the script running?

It’s a normal script in serverScriptService.

What do you mean Player Instance?

I don’t know how to explain it that well so let me give you an example:

game.Players.LocalPlayer -- < Local Player is the player instance

I’m using a normal script. Not a local script.
How can I do this on the script?

1 Like

You can use a for loop to loop through every player.

The script would look like this:

local function SpinnerWalkSpeed(plr)
	local humanoid = plr.Character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 80
	end
end

local function DefaultWalkSpeed(plr)
	local humanoid = plr.Character:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
end

for i, v in pairs(game.Players:GetChildren()) do
--Your function here
end

I still get the error:
`ServerScriptService.RoundScript:24: attempt to index nil with 'Character'`

Have you tried adding the player character first before using the plr parameter?

1 Like

I’m trying to use remote events now:

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)

But this isn’t working either…
Please help

Please elaborate further, thanks! :slight_smile:

local function SpinnerWalkSpeed(plr)
	local humanoid = plr.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 80
	end
end

local function DefaultWalkSpeed(plr)
	local humanoid = plr.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
end

In the script shown above, how are you passing the arguments through to the functions?

What are you passing as “plr”? The actual player, or the player’s character?

Has anyone solved this post yet? Because i think I know something that might work

I already got the script working. Just waiting for his response.

1 Like

Ah I see now, same thing I was going to say, nice work

Oops okay! than i will delete before he is stressing out :smiley:

Sorry for the wait! Been busy.
This doesn’t seem to be working… The character’s walkSpeed is not changing. There is nothing in the output. ( it is also not printing.)

I also tried yours, it also doesn’t do anything. And there’s nothing in the output