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
Use :GetService()
to retrieve the Players
Service
KeyDown()
is deprecated, so use the UserInputService
instead
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)
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