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

Script to sprint with animation(using the animate script's animations)?

Asked by
Jo_Bot 67
6 years ago
if not game.Players.LocalPlayer.Character then
    wait()
end

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local chr = plr.Character

while true do
walkAnim = chr.Animate.walk.WalkAnim
runAnim = chr.Animate.run.RunAnim

UIS.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then
        chr.Humanoid.WalkSpeed = 24
        chr.Humanoid:LoadAnimation(runAnim)
    end
end)

UIS.InputEnded:connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then
        chr.Humanoid.WalkSpeed = 12
        chr.Humanoid:LoadAnimation(walkAnim)
    end
end)

wait()  
end

I feel like this script should work, I have the animation Ids right, so I do not know what the problem is. It is just running the Walk animation. It still changes WalkSpeed though. I set the Run animation to an id, instead of it being run.xml or whatever it usually is. Maybe the problem is in the animation script and not this, I dunno...

1 answer

Log in to vote
0
Answered by 6 years ago

The script needs to be a regular script, and because it needs to be a ordinary script, the script has to be fitted for a ordinary script. Below will be your script, that I have fixed.


-- //Put this in StarterCharacterScripts local UIS = game:GetService("UserInputService") local plr = game.Players:GetPlayerFromCharacter(script.Parent) local chr = plr.Character while true do walkAnim = chr.Animate.walk.WalkAnim runAnim = chr.Animate.run.RunAnim UIS.InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then chr.Humanoid.WalkSpeed = 24 chr.Humanoid:LoadAnimation(runAnim) end end) UIS.InputEnded:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then chr.Humanoid.WalkSpeed = 12 chr.Humanoid:LoadAnimation(walkAnim) end end) wait() end
0
Hmm, still not running the right animation... Jo_Bot 67 — 6y
0
All fixed, chr.Humanoid:LoadAnimation(runAnim) should of been a local variable, then I just ran the animation! Jo_Bot 67 — 6y
Ad

Answer this question