Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I add A humanoid walkspeed in this without breaking it?

Asked by 9 years ago

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.

0
Also, btw on line 9, Is it supposed to be AnimScrip or AnimScript with a "t"? Look at both answers are accept the one that helps you most! First is not always better! EzraNehemiah_TF2 3552 — 9y
0
Nah just AnimScrip 789zaya 0 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

You already know how to get the Humanoid. We can turn it into a variable.


WalkSpeed

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!

0
Thank you for your help and it stays as AnimScrip 789zaya 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.

0
Thanks for the understanding. 789zaya 0 — 9y

Answer this question