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.
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)
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()