I’ve created an animation alongside with a script; however, while the script itself is fine,
the animation for some strange reason moves back to the beginning point then teleporting to the end point.
I’d love to know if there is a way to fix this issue!
-- Here is the script incase if you need it!
local Prompt = script.Parent.Object.Prompt.ProximityPrompt
local isvaulting = false
local Animation = script.Vaulting
local End_Point = script.Parent.End_Point
local Start_Point = script.Parent.Start_Point
Prompt.Triggered:Connect(function(player)
local Playing = player.Character.Humanoid:LoadAnimation(Animation)
if not isvaulting then
player.Character.Humanoid.WalkSpeed = 0
Playing:Play()
isvaulting = true
isontheotherside = true
end
Playing.Ended:Connect(function()
player.Character.Humanoid.WalkSpeed = 16
player.Character.HumanoidRootPart.CFrame = CFrame.new(End_Point.Position)
isvaulting = false
end)
end)
I believe it’s a common issue with animations, where they go back to the idle animation before finishing. Perhaps you should move the player’s CFrame instead of animating it (so that they go back to the idle animation at where they finish vaulting, rather than where they started vaulting).
It’s pretty easy actually, you can do it on one or two lines, but I have trust issues with the garbage collector (memory leaks are serious), so I’ll need to add in 2 more lines.
local TweenService = game:GetService("TweenService")
local Prompt = script.Parent.Object.Prompt.ProximityPrompt
local isvaulting = false
local Animation = script.Vaulting
local End_Point = script.Parent.End_Point
local Start_Point = script.Parent.Start_Point
Prompt.Triggered:Connect(function(player)
local Playing = player.Character.Humanoid:LoadAnimation(Animation)
if not isvaulting then
player.Character.Humanoid.WalkSpeed = 0
-- We put this code here to prevent unnecessary processing power waste
-- Create info for the tween
local TI = TweenInfo.new(--[[PUT ANIMATION DURATION HERE]], Enum.EasingStyle.Linear)
-- Create the tween
local cframeTween = TweenService:Create(player.Character.HumanoidRootPart,TI,{CFrame = CFrame.new(End_Point.Position)})
cFrameTween:Play() -- Play the tween
Playing:Play()
isvaulting = true
isontheotherside = true
end
Playing.Ended:Connect(function()
player.Character.Humanoid.WalkSpeed = 16
isvaulting = false
cFrameTween:Destroy() -- Destroy the tween (just in case)
end)
end)
Oh yeah, I just had a look at the documentation (I’m pretty slow) and Cog is right, you should probably be using Stopped. Not sure if you’ll still see any funky stuff with the animation fade-out though.
Alright, I think I managed to fix it, thank you @TestyLike3 and @CogTheSuit for your help, I’ll mark @TestyLike3 's solution incase if anyone had the same issues as me.