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
6 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

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()

local SD = game.Workspace.SittingDown
SD.AnimationId = "http://www.roblox.com/asset/?id=933356177" 

local S = game.Workspace.Seated
SD.AnimationId = "http://www.roblox.com/asset/?id=933369397" 

mouse.KeyDown:connect(function(key)
    if key == "z" then 
        local playAnim = humanoid:LoadAnimation(SD)
        playAnim:Play()
        wait(1.6)
        local playAnim = humanoid:loadAnimation(S)
        playAnim:Play()

    end
end)
1
Try using UserInputService thesit123 509 — 6y

1 answer

Log in to vote
0
Answered by 6 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

--This needs to be inside a localscript, otherwise will not work
local service=game:GetService("UserInputService")

service.InputBegan:connect(function(obj)
    if obj.KeyCode==Enum.KeyCode.Z then
            local playAnim = humanoid:LoadAnimation(SD)
        playAnim:Play()
            wait(1.6)
            local playAnim = humanoid:loadAnimation(S)
            playAnim:Play()
    end
end

--this is the function to make you press a button that does something, example, pressing Shift ------does make you run
Ad

Answer this question