Added a TweenInfo for the sliding duration and modified the easing style and direction.
Removed the for loop that multiplies the force by 1 repeatedly, as it doesn’t serve any purpose.
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local CanSlide = true
local SlideForce = 50 -- Define your slide force value here
local SlideDuration = 0.8 -- Define your slide duration here
local function onKeyDown(i)
if i.KeyCode == Enum.KeyCode.LeftAlt and CanSlide then
CanSlide = false
local Char = game.Players.LocalPlayer.Character
local Hum = Char:FindFirstChild("Humanoid")
local SlideAnimation = Instance.new("Animation") -- Create a new Animation object here or use a pre-defined one
SlideAnimation.AnimationId = "rbxassetid://YOUR_ANIMATION_ID" -- Replace with your sliding animation asset ID
local Slide = Instance.new("BodyVelocity", Char.HumanoidRootPart)
Slide.MaxForce = Vector3.new(SlideForce, 0, SlideForce)
Slide.Velocity = Char.HumanoidRootPart.CFrame.LookVector * Vector3.new(SlideForce, 0, SlideForce)
local T = Hum:LoadAnimation(SlideAnimation)
T:Play()
local tweenInfo = TweenInfo.new(SlideDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(Slide, tweenInfo, {Velocity = Vector3.new(0, 0, 0)})
tween:Play()
tween.Completed:Wait()
Slide:Destroy()
T:Stop()
CanSlide = true
end
end
UserInputService.InputBegan:Connect(onKeyDown)