How to store a player's original walkspeed as a local variable?

So in my game, players can have different walk speeds, I just want to know how I can like store their original walk speed value into a variable. Because basically, I want to change the player’s walk speed to 0 then change it back to their original walk speed.

Blade.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
local originalwalkspeed = Humanoid.WalkSpeed
Humanoid.WalkSpeed = 0
wait(5)
Humanoid.WalkSpeed = originalwalkspeed

That should work, why doesn’t it?

If it doesn’t work, try to use tonumber to make it a number and not a reference variable.

in the output it just says attempt to index nil with walkspeed.

That means humanoid is nil, please consider showing the entire script.

I just edited the post. I don’t know if I need to show more though.

check if actually a character touched to it by adding if Hit.Parent:FindFirstChild("Humanoid") then before doing stuff

1 Like

This should work.

Blade.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
local originalwalkspeed = Humanoid.WalkSpeed
humanoid.WalkSpeed = 0
wait(5)
Humanoid.WalkSpeed = originalwalkspeed
end
1 Like

It’s because you misspelled your humanoid variable without a capital H on your first WalkSpeed set.

1 Like