Help with fixing a sliding script

I have a script for a sliding animation for my game and it dose not work and i dont know why i will post my code below

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

local SA = Instance.new("Animation")
SA.AnimationId = "rbxassetid://10791226196"

local keybind = Enum.KeyCode.LeftControl
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(SA)
		playAnim:Play()
		
		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.LookVector * 100
		slide.Parent = char.HumanoidRootPart
		
		for count 1, 8 do
			wait(0.1)
			slide.Velocity *= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		wait(1)
		canslide = true
	end
end)

can somebody please help
and also i wanna note i am new to making games and scripting

have you inserted print statements or a breakpoint to confirm the playanim successfully runs? If your animation is not saved as priority ‘action’ it may just be overridden by a higher priority animation so you dont see it when it ‘plays’. If you find that is the case, in the animation editor you want to re-save the animation with an ‘action’ priority.

It is a action priority because it doesnt even increese speed or anything

hello? you there?

{ingore this}

do you know any other solutions?

Anybody else know what i can do?

does the output show any errors? can you provide a video of what is happening in game?

There are a few errors you can end up with.

  • The animation is being played on a localscript, which will cause it to only play on the client’s side.

  • You do not own the animation.

  • You are developing with more than 1 player, upload the animation to a group.

Cant really becuase nothing happens the player just keeps walking normally (speed does not inscrese nor does the animation play)

Should it be put on a normal script

UserInputService will only work with LocalScripts, you need to use a RemoteEvent to use the animation.

Something like this:

AnimationEvent.OnServerEvent:Connect(function(plr, animID)
local character = plr.Character
local anim = Instance.new("Animation")
anim.AnimationId = animID
character.Humanoid:LoadAnimation(anim):Play()
end)
1 Like

where can i put this in the script?

On playanim, replace it with AnimationEvent:FireServer(animID)

i think im just blind i cant find what your talking about

i dont know where it is i cant find it in the code

local playAnim = char.Humanoid:LoadAnimation(SA)
playAnim:Play()

Use Animator instead and set the priority

local Animator = char.Humanoid:FindFirstChild("Animator")
local playAnim

if Animator then
   playAnim = Animator:LoadAnimation(SA)
end

playAnim.Priority = Enum.Priority.Action4
playAnim:Play()