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

How to make character stay in position after animation ends?

I made this dash script in which the player will move 5 studs forward. But the character go back to where it was after the animation ends.

script.Parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		local attack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Attack)
		attack:Play()		
	end)
end)	

3 comments

0

Maybe you could put the character in the pose of the dash and then move the CFrame of the humanoid forward so the actual roblox character is moving forward?

0

how can i do that?

0

edit the animation so it plays the dash but doesn't move the charatcher in any direction the use the CFrame to move the character

2 answers

(I'm not a pro and haven't tested it but I can try)

You would add the CFrame maybe like this:

script.Parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
	local human = game.Players.LocalPlayer.Character.Humanoid
        local attack = human:LoadAnimation(script.Attack)
        attack:Play() 
	human.CFrame = CFrame.new(human.Position + Vector3.new(0,5,0))
    end)
end)    

3 comments

0

it said 'Position is not a valid member of Humanoid' how should i fix this?

0

human.CFrame

0

or humanoid.CFrame.Position

The solution to this problem is actually a relatively messy solution, unfortunately. I had a similar situation with a dash animation, and it took a while to get a full solution on how to make it stay in the final position.

Basically, you have to add a new keyframe right before the end of the animation. You need to name this keyframe "Pause". Then, you can use AddMarker function of Keyframe. Once you have the marker setup, you can use the event of the animation GetMarkerReachedSignal to detect when the newly added marker is reached. When the marker is reached, you need to pause the player in this part of the animation so that it avoids the natural behavior of returning the player to their initial position. You may have to tweak the animation a little for this, but this is the only reliable way I found to do it.

1 comment

0

i dont really understand. sorry

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