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

how do i make te player go the to position at the end of a animation?

So basically, i have a script where u press a key and play a animation, expect the animation slides the character back to its OG position instead of the character going to the position that the animation ended in. Any help fellow peeps?

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

  

function keyD(key)

local key = key:lower()

local hotkey = script.Hotkey.Value

if key == hotkey then

local dance = Instance.new("Animation")

--only change this

dance.AnimationId = "rbxassetid://02937579947"

--nothing above or below

local animloader = player.Character.Humanoid:LoadAnimation(dance)

animloader:Play()

end

end

  

mouse.KeyDown:connect(keyD)

--UHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH bonlesss burger

4 comments

0

Show us your script and we'll help you out.

0

Animations will not change the position of your character, you'll have to move it as well by editing it's CFrame some way, or tween it while animation (stationary) like most things work.

0

Edit:- code block

0

use scratch instead

1 answer

✓ Accepted answer

General Practice

Use :GetService() to retrieve the Players Service

Issues

KeyDown() is deprecated, so use the UserInputService instead

Revised Local Script

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

local dance = Instance.new("Animation")
dance.AnimationId = "rbxassetid://02937579947"
local animloader = player.Character:WaitForChild("Humanoid"):LoadAnimation(dance)

game:GetService("UserInputService").InputBegan:Connect(function(input, event)
    if input.KeyCode == Enum.KeyCode.D then
	    animloader:Play()
    end
end)

animloader.KeyframeReached:Connect(function(keyframeName)
    if keyframeName == "Pause" then
	    animloader:AdjustSpeed(0)
    end
end)

Explanation

Whatever your "script.Hotkey.Value" is, use the corresponding KeyCode Enum with the U.I.S.

The second function pertains to the KeyframeReached event of the AnimationTrack. In order to use it for this, you must name the second to last keyframe to match the "keyframeName" (in my example, this is named "Pause") This means you will have to re-upload the animation with the updated keyframe name.

The AdjustSpeed function of an AnimationTrack changes the duration of the animation (when set to zero, the pose will freeze in its current place)

Please note that this script is run on the Client so any and all changes will not be replicated to the Server as a result of FilteringEnabled

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