Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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 comment

1

Try using UserInputService

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.