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

Animation won't play when shift is pressed?

Asked by 4 years ago

Hi, I made a sprint script and tried to make an animation play when I press shift. Only problem is, it won't play. I tried adjusting the priority and put it in different parts of the script but it doesn't work.

01local anim = Instance.new("Animation")
02anim.AnimationId = "rbxassetid://2510238627"
03 
04local plr = game:GetService("Players").LocalPlayer
05local mouse = plr:GetMouse()
06 
07local char = plr.Character or plr.CharacterAdded:Wait()
08local human = char:WaitForChild("Humanoid")
09 
10local track = human:LoadAnimation(anim)
11track.Priority = Enum.AnimationPriority.Action
12 
13mouse.KeyDown:Connect(function(k)
14    if k:lower():byte() == 48 then
15        track:Play()
View all 25 lines...

1 answer

Log in to vote
1
Answered by 4 years ago

Hello. Try using UserInputService as Mouse.KeyDown is deprecated. Try this:

01local UserInputService = game:GetService("UserInputService")
02 
03local anim = Instance.new("Animation")
04anim.AnimationId = "rbxassetid://2510238627"
05 
06local plr = game:GetService("Players").LocalPlayer
07local mouse = plr:GetMouse()
08 
09local char = plr.Character or plr.CharacterAdded:Wait()
10local human = char:WaitForChild("Humanoid")
11 
12local track = human:LoadAnimation(anim)
13track.Priority = Enum.AnimationPriority.Action
14 
15UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
View all 27 lines...

The InputBegan function fires when an input is detected. Then there's an if statement checking if the input is left shift and that the player isn't in chat. Then it plays the animation and changes the walkspeed.

0
It works, but my animation doesn't change. It's supposed to change my walking animation to the animation in the script. mybituploads 304 — 4y
0
If it matters I'm using the werewolf run animation mybituploads 304 — 4y
0
Try setting the animation's priority inside the animation editor. youtubemasterWOW 2741 — 4y
0
Nevermind, the animation ID was incorrect. mybituploads 304 — 4y
0
oof youtubemasterWOW 2741 — 4y
Ad

Answer this question