Hi, I am making a slide script and I want to slowly deaccelerate the slide using a while loop.
I currently have no way of doing it so any help would be helpful of course lol.
if actionName == "Slide" and inputState == Enum.UserInputState.Begin and not Debounce and Humanoid then
Debounce = true
local FieldOfViewOut = TweenService:Create(workspace.CurrentCamera,TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{FieldOfView = 80})
local FieldOfViewIn = TweenService:Create(workspace.CurrentCamera,TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{FieldOfView = 70})
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local direction = HumanoidRootPart.Position + HumanoidRootPart.CFrame.LookVector
local bottomResult = workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0,-100,0), raycastParams)
local wallResult = workspace:Raycast(HumanoidRootPart.Position, direction, raycastParams)
if bottomResult then -- this checks if the players bottom ray is too high up
local Distance = math.round(bottomResult.Distance)
if bottomResult.Distance <= 10 then
print("Enough distance to slide: "..Distance)
else
print("Not enough to slide: "..Distance)
end
end
local SlideSpeed = (Humanoid.WalkSpeed * 2)
local Attachment = Instance.new("Attachment")
Attachment.Parent = HumanoidRootPart
local Accelerate = Instance.new("LinearVelocity")
Accelerate.Parent = HumanoidRootPart
Accelerate.MaxForce = math.huge
Accelerate.VectorVelocity = HumanoidRootPart.CFrame.LookVector * SlideSpeed
Accelerate.Attachment0 = Attachment
FieldOfViewOut:Play()
local WallCheck = RunService.Stepped:Connect(function(dt)
if wallResult then
print(wallResult.Instance)
end
end)
print(Accelerate.VectorVelocity)
while Accelerate.VectorVelocity > 0 do
Accelerate.VectorVelocity -= 1
print(Accelerate.VectorVelocity)
end
WallCheck:Disconnect()
FieldOfViewIn:Play()
Debounce = false
end
end