Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited by User#5423 5 years ago

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?

```lua 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

0
Show us your script and we'll help you out. songboy50 77 — 5y
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. gullet 471 — 5y
0
Edit:- code block User#5423 17 — 5y
0
use scratch instead greatneil80 2647 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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

Ad

Answer this question