-- 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?