Animation is glitching out

I’m trying to make a slide ability, the moving forward using a script when a key is pressed works fine.
But the animation for the slide ability is completely broken, it does sort of play but heavily glitches back and forth from the default walking animation to the slide animation

This video shows the issue.

-- variables and get service
local UIS = game:GetService("UserInputService")
local keybind = Enum.KeyCode.LeftShift
local Cancel = Enum.KeyCode.Space
local canslide = true

local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')
local Humanoid = char:FindFirstChild("Humanoid")

local loop = true
local SlideAnim = Instance.new("Animation")
local animator = Instance.new("Animator", Humanoid)
SlideAnim.AnimationId = "rbxassetid://14430935628"


UIS.InputBegan:Connect(function(input,gameProcessed)
	if gameProcessed then return end
	if not canslide then return end
	if input.KeyCode == keybind then
		if freefall == true then -- dashes if in the air
			canslide = false
			print("You have dashed")
			
			local dash = Instance.new("BodyVelocity")
			dash.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			dash.Velocity = char.HumanoidRootPart.CFrame.lookVector * 70
			dash.Parent = char.HumanoidRootPart

			for count = 1, 2 do
				wait(0.1)
				dash.velocity *= 0.7
			end
			
			dash:Destroy() -- destroys instance once finished
			wait(0.3)
			canslide = true
		else
			canslide = false -- slides if on ground
			print("You have slided")
			
			local playAnim = animator:LoadAnimation(SlideAnim)
			playAnim:Play()
			
			local slide = Instance.new("BodyVelocity") -- pushes player in direction
			slide.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
			slide.Parent = char.HumanoidRootPart
			
			for count = 1, 6 do
				wait(0.1)
				slide.velocity *= 0.7
			end
			playAnim:Stop()
			slide:Destroy()
			canslide = true
		end
		
		
			
	end
	
end)

while loop == true do wait(0.1) -- detects if the player is in the air or on the ground.
	if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		freefall = true
	else
		freefall = false
	end
end

This script also contains another system for dashing when in mid-air, which is what the loop at the bottom is for. I am unsure if this will affect the animation problem, but it is good to note.

you have a wrong approach to loading and playing animations in ur script:

u load the animation over and over everytime the player slides:

local playAnim = animator:LoadAnimation(SlideAnim)
			playAnim:Play()

and also, you don’t have to make a new animator for the humanoid, the default character already has one.

instead, do this:

local loop = true
local SlideAnim = Instance.new("Animation")
SlideAnim.AnimationId = "rbxassetid://14430935628"

local playAnim = Humanoid:LoadAnimation(SlideAnim)


and in the function, just do

playAnim:Play()
1 Like

the script would look like this in the end:

-- variables and get service
local UIS = game:GetService("UserInputService")
local keybind = Enum.KeyCode.LeftShift
local Cancel = Enum.KeyCode.Space
local canslide = true

local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')
local Humanoid = char:FindFirstChild("Humanoid")

local loop = true
local SlideAnim = Instance.new("Animation")
SlideAnim.AnimationId = "rbxassetid://14430935628"

local playAnim = Humanoid:LoadAnimation(SlideAnim)

UIS.InputBegan:Connect(function(input,gameProcessed)
	if gameProcessed then return end
	if not canslide then return end
	if input.KeyCode == keybind then
		if freefall == true then -- dashes if in the air
			canslide = false
			print("You have dashed")
			
			local dash = Instance.new("BodyVelocity")
			dash.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			dash.Velocity = char.HumanoidRootPart.CFrame.lookVector * 70
			dash.Parent = char.HumanoidRootPart

			for count = 1, 2 do
				wait(0.1)
				dash.velocity *= 0.7
			end
			
			dash:Destroy() -- destroys instance once finished
			wait(0.3)
			canslide = true
		else
			canslide = false -- slides if on ground
			print("You have slided")
			
			playAnim:Play()
			
			local slide = Instance.new("BodyVelocity") -- pushes player in direction
			slide.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
			slide.Parent = char.HumanoidRootPart
			
			for count = 1, 6 do
				wait(0.1)
				slide.velocity *= 0.7
			end
			playAnim:Stop()
			slide:Destroy()
			canslide = true
		end
		
		
			
	end
	
end)

while loop == true do wait(0.1) -- detects if the player is in the air or on the ground.
	if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		freefall = true
	else
		freefall = false
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.