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

how to stop an animation from rewinding when stopped?

when I run my animation it will run then rewind back and go back to normal. in making a crouch feature so I don't want it to rewind here is my code

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

function onKeyPress(inputObject, gameProcessed)
	print("key pressed")
	print(inputObject.KeyCode)
	if inputObject.KeyCode == Enum.KeyCode.E then
		print("E pressed")
		local humanoid = player.Character:WaitForChild("Humanoid")
		local ani = humanoid:LoadAnimation(game.animations.Animation)

		ani:Play()
		ani.Stopped:Connect(function()
			print("stopped")
		end)	
	end
	end



UserInputService.InputBegan:Connect(onKeyPress)

this code technically works but it doesn't do exactly what I want to do. I want it to stay crouching but instead, it crouches then stands back up

UserInputService.InputBegan:Connect(onKeyPress)

1 comment

0

try by not loading the animation onto the humanoid inside of the function, put it outside so it only loads once. second off, humanoid:LoadAnimation has become deprecated, you should be using humanoid.Animator:LoadAnimation but keep in mind that the animator has to be created server side and then parented to the humanoid

1 answer

✓ Accepted answer

The problem is the animation isn't looping. Once the animation finishes playing, it stops then goes back to the idle animation. You could make it loop via the script but I prefer doing it in animation editor just so the script is one line shorter.

https://gyazo.com/c1178a8b222f4f79902b93cbb08feea8

3 comments

0

then i press E then it just headbangs

0

Make sure there's only 1 keyframe which is the crouched position. Don't animate the in betweens.

0

ok

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