Trying to make a smooth slide system

-- Services
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")

-- Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local slideAnimation = humanoid:LoadAnimation(Instance.new("Animation"))
slideAnimation.AnimationId = "rbxassetid://119653119436920" -- Replace with your animation ID

-- Sliding Parameters
local slideSpeed = 50
local slideDuration = 0.5
local isSliding = false
local slideCooldown = 1
local canSlide = true

-- Function to start sliding
local function startSlide()
	if isSliding or not canSlide then return end

	isSliding = true
	canSlide = false

	-- Play sliding animation
	slideAnimation:Play()

	-- Apply velocity for sliding
	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge) -- Only allow X and Z movement
	bodyVelocity.Velocity = rootPart.CFrame.LookVector * slideSpeed
	bodyVelocity.Parent = rootPart

	Debris:AddItem(bodyVelocity, slideDuration)

	-- Stop sliding after duration
	wait(slideDuration)
	isSliding = false

	-- Cooldown before allowing sliding again
	wait(slideCooldown)
	canSlide = true
end

-- Detect Shift or Ctrl key press
UserInputService.InputBegan:Connect(function(input, isProcessed)
	if isProcessed then return end -- Ignore if input is already processed by other scripts

	if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.LeftControl then
		startSlide()
	end
end)

-- Reset sliding if the character dies or respawns
player.CharacterAdded:Connect(function(newCharacter)
	character = newCharacter
	humanoid = character:WaitForChild("Humanoid")
	rootPart = character:WaitForChild("HumanoidRootPart")
end)

thisis the code i have made through chatgpts help but it does not work, i just want to simply have a smooth slide that slows down and i can cancel whenever i want just like how it works in games like parkour reborn, anyone know why?

1 Like

Your script attempts to load the animation before the AnimationId is set, causing the script to error. You can fix it by changing this (on line 12):

local slideAnimation = humanoid:LoadAnimation(Instance.new("Animation"))
slideAnimation.AnimationId = "rbxassetid://119653119436920" -- Replace with your animation ID

to something like this:

local slideAnimationObj = Instance.new("Animation")
slideAnimationObj.AnimationId = "rbxassetid://119653119436920" -- Replace with your animation ID
local slideAnimation = humanoid:LoadAnimation(slideAnimationObj)

This way it does not error when attempting to load the animation because you create an Animation object which has the AnimationId set.

1 Like

thanks so much it for responding, it has made my script work but it does not slowdown with an ability to stop it at any time if yk what i mean, would you know what i would need to do to make it work?

Did you solve this or is it still an issue

the slide works but the smoothness is a bit off and i still cant slide cancel, would you have any ideas to how to complete it?