Sliding Ability not Working

Hey there, I want to have a Sliding Ability in my game and it doesn’t seem to be working.

The thing is when i test it doesn’t work and the Output has no Errors

The Script: In StarterCharacterScripts and the Animation is inside the script

In Game:

Output:
image

I looked for some solutions but they don’t seem to help, so i came here to see if anyone knew.

The Script’s Code:

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

local SlideAnimation = script:WaitForChild("SlideAnimation")

local CanSlide = true

UserInputService.InputBegan:Connect(function(Input,GameProcessed)
	if not GameProcessed then return end
	
	if Input == Enum.KeyCode.LeftControl then
		if CanSlide == true then
			CanSlide = false

			local PlayAnimation = Character.Humanoid.Animator:LoadAnimation(SlideAnimation)
			PlayAnimation:Play()

			local Slide = Instance.new("BodyVelocity")
			Slide.MaxForce = Vector3.new(1,0,1) * 30000
			Slide.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 100
			Slide.Parent = Character.HumanoidRootPart
			CanSlide = false
			wait(.8)
			PlayAnimation:Stop()
			Slide:Destroy()
			wait(4.2)
			CanSlide = true
		end
	end
end)

Is it a Local Script? If it is, put it in the player’s backpack and try.
If you get an error such as the character was identified as nil, try using game.Players.LocalPlayer.CharacterAdded:Wait().

I have put the Script into StarterPack and changed the “Character” line to do “game.Players.LocalPlayer.CharacterAdded:Wait()” and it is still not Working.

Can you make a print course all over your script? What I mean by that is adding prints everywhere on your script and see where it breaks.

I added 6 prints in the script and it seems to break after the 2nd print (0 being the first and 1 being the second)


image

if Input == Enum.KeyCode.LeftControl then

Try adding .KeyCode after Input.

1 Like

It Works!

Thanks for taking the time to help me fix this!

1 Like

No problem! It’s a pleasure to help.

2 Likes