[Animation Scripting] Need some help on some animation scripting

So basically I’m trying to make a animation where the character sits down than lays down after it sits but right after that how can I make it where the player stays at the lay down position until they start walking again (aka using the w,a,s,d keys I guess)

 local player = game.Players.LocalPlayer
 repeat wait() until player.Character
 local character = player.Character
 local mouse = player:GetMouse()
 local timePosition = 3
 local percentagePosition = 99
 local animation = Instance.new("Animation")
 animation.Name = "HandsUp"
 animation.AnimationId = "rbxassetid://3336575859"
 track = character:WaitForChild("Humanoid"):LoadAnimation(animation)
 
 mouse.KeyDown:Connect(function(key)
 		if key == "x" then
 		track:Play()
 	end
 end)
2 Likes

You can put the animation on looped and when they click arrow keys or w,a,s,d, you can stop the animation.

You should use GetMarkerReachedSignal and Set Animation events in the animation editor. What I do is I set one an event named End right as I want it to stop toward the end of the animation. Then when it fires I set the speed of the animationtrack to 0 which stops and holds the animation in that position. Then if you wanted to stop it all the way just use animTrack:Stop() later when the player moves or presses wsad. You can also set position of the animation track using something like animTrack.TimePosition = 1.48

Below is code to catch the Event named End and set speed to 0

local animTrack = AnimationController:LoadAnimation(Animation)
			animTrack:GetMarkerReachedSignal("End"):Connect(function()
			animTrack:AdjustSpeed(0)
		end)
		animTrack:Play()

This is how you add them in editor by Right clicking in that area
image

and then just set and save the name