I made a sliding animation for a football (soccer) game that is meant to be looped. It’s only one keyframe, that’s why I looped it, so that I can stop it whenever I want.
When my character walks, it works perfectly:
But when I am standing still, it bugs out or something:
This happened just now and worked perfectly fine before.
This is my script I use to make the player slide, no other scripts involved:
local UIS = game:GetService("UserInputService")
local char = script.Parent
local slideAnim = script:WaitForChild("SlideAnimation")
local keybind2 = Enum.KeyCode.Space --key code
local canslide = true
local boughtspeed = false
local function slide()
if char:WaitForChild("Slowed").Value == false then
if char.Humanoid.WalkSpeed == 30 then
boughtspeed = true
end
canslide = false
game.ReplicatedStorage.isSliding:FireServer()
local playAnim = char.Humanoid.Animator:LoadAnimation(slideAnim)
playAnim.Looped = true
playAnim:Play()
local slide = Instance.new("BodyVelocity")
slide.MaxForce = Vector3.new(1,0,1)*37500
slide.Velocity = char.HumanoidRootPart.CFrame.lookVector*75
slide.Parent = char.HumanoidRootPart
for count = 1,8 do
wait(0.1)
slide.Velocity*=0.8
end
playAnim:Stop()
slide:Destroy()
if char.Slowed.Value == true then
char.Humanoid.WalkSpeed = 0
end
game.ReplicatedStorage.isSlidingDone:FireServer()
wait(5)
canslide = true
else
return
end
end
UIS.InputBegan:Connect(function(input,gameprocessed)
if gameprocessed then return end
if not canslide then return end
if input.KeyCode == keybind2 then
slide()
end
end)
As you can see, I have added a function called slide(). The script inside the function is exactly the same as to what was where this function is called now:
if input.KeyCode == keybind2 then
slide()
end
This is very weird, as I have made no changes to the way the sliding works, only added it in a function. It’s also weird that it only works when moving and not when standing still.
Thank you for reading, please help me if you know the issue.