Can someone help me with my sliding script?

Hello i maked a sliding script for a game that i’m currently working on and the script has a bug that gives a tiny speed boost.
Can someone help me?

Video showing the bug

The script:

local UIS = game:GetService("UserInputService")
local char = script.Parent

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://6577673005" --Animation ID
local keybind = Enum.KeyCode.E
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end
	
	if input.KeyCode == keybind then
		canslide = false
		
		local playAnim = char.Humanoid:LoadAnimation(slideAnim)
		playAnim:Play()
		
		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(0.2,0,0.2) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
		slide.Parent = char.HumanoidRootPart
		
		for count = 1, 8 do
			wait(0.1)
			slide.Velocity *= 0.5
			
		end
		playAnim:Stop()
		slide:Destroy()
		canslide = true
	end
end)
1 Like

just a quick tip

don’t use Humanoid:LoadAnimation(), it’s deprecated and instead use animator:LoadAnimation()

why don’t you just load the animation outside the function so it doesn’t have to load it every time the player presses E?

2 Likes

Oh thanks! im new at scripting

1 Like

it just says
16:51:39.956 animator is not a valid member of Model “Workspace.xWhiteDip” - Client - SlideScript:17

its because a model cant have an animator.

--try
workspace[the character model].Humanoid.Animator:LoadAnimation(id)
1 Like

it gives just a error in output:
16:59:42.867 Workspace.xWhiteDip.SlideScript:17: Expected ‘]’ (to close ‘[’ at column 34), got ‘character’ - Studio - SlideScript:17

replace that on your character thing
the char

like this?
char.workspace[char].Humanoid.Animator:LoadAnimation(slideAnim)

workspace[char].Humanoid.Animator:LoadAnimation(slideAnim)

This is how the full line of the script looks
local playAnim = workspace[char].Humanoid.Animator:LoadAnimation(slideAnim)

now try to play the animation *30charrs

If i test the game it says an error:
17:12:09.486 Workspace.xWhiteDip.SlideScript:17: invalid argument #2 (string expected, got Instance) - Client - SlideScript:17