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

Why isn't this OnKeyDown script playing the first animation?

Asked by
Kimuyo 13
7 years ago

so my idea was when you press z it plays an animation of you sitting down and then 1.6 seconds later it plays the looping seated animation .

what happens is if you press z nothing happens and if you press it again you are seated.

its skipping the sitting down animation

any help i can get is appreciated

01local player = game.Players.LocalPlayer
02repeat wait() until player.Character.Humanoid
03local humanoid = player.Character.Humanoid
04local mouse = player:GetMouse()
05 
06local SD = game.Workspace.SittingDown
08 
09local S = game.Workspace.Seated
11 
12mouse.KeyDown:connect(function(key)
13    if key == "z" then
14        local playAnim = humanoid:LoadAnimation(SD)
15        playAnim:Play()
View all 21 lines...
1
Try using UserInputService thesit123 509 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

If you want to make a key input use UserInputService

there is 2 ways, the first way is the more right way, but the other way if you want a "looped" check

01--This needs to be inside a localscript, otherwise will not work
02local service=game:GetService("UserInputService")
03 
04service.InputBegan:connect(function(obj)
05    if obj.KeyCode==Enum.KeyCode.Z then
06            local playAnim = humanoid:LoadAnimation(SD)
07        playAnim:Play()
08            wait(1.6)
09            local playAnim = humanoid:loadAnimation(S)
10            playAnim:Play()
11    end
12end
13 
14--this is the function to make you press a button that does something, example, pressing Shift ------does make you run
Ad

Answer this question