How do I change the humanoid walkspeed to 24 then when the animation stops the walkspeed resets to 16?
This script already works (Its a running anim script) I just want the walkspeed to 24 when I press Q and 7 seconds later, I want the Walkspeed to return to 16
wait(2) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() Mouse.KeyDown:connect(function(key) if key == "q" then s = player.Character.Humanoid:LoadAnimation(game.StarterPack.AnimScrip.Animation) s:Play() wait(7) s:Stop() end end) local Walk =game.Players.LocalPlayer.Humanoid local Mouse = player:GetMouse() Mouse.KeyDown:connect(function(key) if key == "q" then Walk.WalkSpeed = 24 wait(7) Walk.WalkSpeed = 16 end end)
I've tried many times, now I need assistance.
You already know how to get the Humanoid. We can turn it into a variable.
WalkSpeed is a normal property. WalkSpeed is nothing else than the Max amount velocity your torso or humanoidrootpart can go in a X and Z value, meaning that the max velocity of your X value and Z value is always 16 at default. We can change it to 24 and back to 16 by changing the value like changing a boolean. WalkSpeed = 24
, WalkSpeed = 16
.
We add this to your script, here is the finished script, with some edits.
wait(2) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local humanoid = player.Character:FindFirstChild("Humanoid") --Humanoid Mouse.KeyDown:connect(function(key) if key:lower() == "q" and humanoid then --I added ":lower()" incase they had caps lock on. I also added "and humanoid" just to see if it exists. s = humanoid:LoadAnimation(game.StarterPack.AnimScrip.Animation) s:Play() humanoid.WalkSpeed = 24 --Change the speed wait(7) s:Stop() humanoid.WalkSpeed = 16 --Change the speed end end)
Hope it helps!
The Player
object does not have a Humanoid, you'd be looking for the character. Instead, you should use your regular code, but rather, game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = x
. Also, just to save you some keystrokes, I'd recommend setting game.Players.LocalPlayer.Character.Humanoid
as a variable so that you can easily reference it multiple times.