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

Why doesn't my Looped Animation stop OnKeyDown?

when the player presses z they are seated and when they press x they play a standing up animation that leads into the idle animation

problem is the seated animation is looped and i don't know how to stop the Seated animation

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

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

mouse.KeyDown:connect(function(key)
	if key == "x" then 
		local player S = humanoid:Animation(S)
		S:Stop()
		local playAnim = humanoid:LoadAnimation(SU)
		playAnim:Play()
		wait(2)
		player.Character.Humanoid.WalkSpeed = 16
		
	end
end)

1 comment

0

On line 14 it you needed to do local player = humanoid:LoadAnimation(S)

1 answer

Very minor fixes

local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
repeat wait() until humanoid
local mouse = player:GetMouse()
local Seat = workspace.Seated --You could do workspace instead game.Workspace
S.AnimationId = "http://www.roblox.com/asset/?id=933369397"

local SU = workspace.StandingUp -- Same thing here
SU.AnimationId = "http://www.roblox.com/asset/?id=935753167" 

mouse.KeyDown:Connect(function(key) --connect is depricated I reccommend  Connect
    if key == "x" then 
        local S = humanoid:LoadAnimation(S) -- On your script that you showed me the variable had a space plus I changed the name
        S:Stop()
        local playAnim = humanoid:LoadAnimation(SU)
        playAnim:Play()
        wait(2)
        humanoid.WalkSpeed = 16

    end
end)

Hopefully this helped you fix the script that you made :)

3 comments

0

It mostly works but the looped seated animation doesn't stop when I press x

0

Oh idk how

0

Well you can make a gui go to the player gui by touching a part then make an if statment if the screenGui parent is playerGui and probably do the if key == "x" then the rest of the code

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