I am working on a slide script where the player slides after crouching if they were running. I have the character moving in the right direction but I cant seem to be able to change the slide speed. It only seems to happen when I set the MaxForce Y value to 0 so the player doesn’t float off elevated objects while sliding.
Here is my code:
local Slide_Speed = 50
--Check Position
local f = false
local b = false
local l = false
local r = false
local HRP = player.Character.HumanoidRootPart
local hum = player.Character:FindFirstChild("Humanoid")
local idle = hum:LoadAnimation(animation_list.CrouchIdle)
local move = hum:LoadAnimation(animation_list.Crouch)
--Check Position
local f = false
local b = false
local l = false
local r = false
--Check keys pressed
if uis:IsKeyDown(Enum.KeyCode.W) then
f = true
end
if uis:IsKeyDown(Enum.KeyCode.S) then
b = true
end
if uis:IsKeyDown(Enum.KeyCode.A) then
l = true
end
if uis:IsKeyDown(Enum.KeyCode.D) then
r = true
end
--Check if in FPS / Mouse Locked--
local Force_Chosen = nil
if Unsaved.FPS.Value == true or Unsaved.MouseLocked.Value == true then
--Set Force--
if f then
if l then
Force_Chosen = (HRP.CFrame.lookVector * Slide_Speed) + (HRP.CFrame.rightVector * -Slide_Speed)
elseif r then
Force_Chosen = (HRP.CFrame.lookVector * Slide_Speed) + (HRP.CFrame.rightVector * Slide_Speed)
else
Force_Chosen = (HRP.CFrame.lookVector * Slide_Speed)
end
elseif b then
if l then
Force_Chosen = (HRP.CFrame.lookVector * -Slide_Speed) + (HRP.CFrame.rightVector * -Slide_Speed)
elseif r then
Force_Chosen = (HRP.CFrame.lookVector * -Slide_Speed) + (HRP.CFrame.rightVector * Slide_Speed)
else
Force_Chosen = (HRP.CFrame.lookVector * -Slide_Speed)
end
elseif l then
Force_Chosen = (HRP.CFrame.rightVector * -Slide_Speed)
elseif r then
Force_Chosen = (HRP.CFrame.rightVector * Slide_Speed)
end
else
Force_Chosen = HRP.CFrame.lookVector * Slide_Speed
end
--Set up Linear Velocity--
local LV = Instance.new("LinearVelocity")
LV.Parent = HRP.Slide
LV.MaxForce = Vector3.new(math.huge, 0, math.huge)
LV.VectorVelocity = Vector3.new(Force_Chosen.X, 0, Force_Chosen.Y)
LV.Attachment0 = HRP.Slide
local SDA_info = TweenInfo.new(Slide_Time, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local Slide_Distance_Anim = ts:Create(LV, SDA_info, {VectorVelocity = Vector3.new(0,0,0)})
Slide_Distance_Anim:Play()
When MaxForce = Vector3.new(math.huge, 0, math.huge)
robloxapp-20230728-1924385.wmv (2.2 MB)
When MaxForce == math.huge
robloxapp-20230728-2204487.wmv (1.6 MB)
When MaxForce = math.huge, it Tweens correctly and the Slide_Speed Variable works properly where the character slowly stops sliding. Although, the character will float if they slide off an elevated surface. Is there a way I can have the Tween and Variable run properly while maintining gravity? If not, is there is a better method I should go about doing this?