Check for when a player is slowing down

Ive got a script that lets the player slide, i want to know when the players speed has decreased to less than the velocity it would have when walking and then stop the animation.

How could I do that?

local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = script.Parent.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local HumRootPart = Character:WaitForChild("HumanoidRootPart")

--99893655201485

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://137477863876911"

local Animation2 = Instance.new("Animation")
Animation2.AnimationId = "rbxassetid://99893655201485"


local SlideStartTrack = Animator:LoadAnimation(Animation)
local SlideContinuousTrack = Animator:LoadAnimation(Animation2)


UIS.InputBegan:Connect(function (input)
	if input.KeyCode == Enum.KeyCode.C then
		SlideStartTrack:Play()
		SlideStartTrack:AdjustSpeed(3)
		SlideStartTrack.Ended:Connect(function ()
			SlideContinuousTrack:Play()
		end)
		local LinearVelocity = Instance.new("LinearVelocity")
		LinearVelocity.Parent = HumRootPart
		LinearVelocity.Attachment0 = HumRootPart.RootAttachment
		LinearVelocity.MaxForce = 100000
		LinearVelocity.VectorVelocity = HumRootPart.CFrame.LookVector * 100
		LinearVelocity.Enabled = true
		wait(0.5)
		LinearVelocity:Destroy()
		task.wait(0.1)
	end
end)


maybe try HumanoidRootPart.Velocity?

1 Like

I would but isn’t Velocity deprecated?

My bad, maybe HumanoidRootPart.AssemblyLinearVelocity?*

That was it, got it working

local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = script.Parent.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local HumRootPart = Character:WaitForChild("HumanoidRootPart")

--99893655201485

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://137477863876911"

local Animation2 = Instance.new("Animation")
Animation2.AnimationId = "rbxassetid://99893655201485"


local SlideStartTrack = Animator:LoadAnimation(Animation)
local SlideContinuousTrack = Animator:LoadAnimation(Animation2)


UIS.InputBegan:Connect(function (input)
	if input.KeyCode == Enum.KeyCode.C then
		SlideStartTrack:Play()
		SlideStartTrack:AdjustSpeed(3)
		SlideStartTrack.Ended:Connect(function ()
			SlideContinuousTrack:Play()
		end)
		local LinearVelocity = Instance.new("LinearVelocity")
		LinearVelocity.Parent = HumRootPart
		LinearVelocity.Attachment0 = HumRootPart.RootAttachment
		LinearVelocity.MaxForce = 100000
		LinearVelocity.VectorVelocity = HumRootPart.CFrame.LookVector * 200
		LinearVelocity.Enabled = true
		wait(0.5)
		LinearVelocity:Destroy()
		task.wait(0.1)
		
		print(HumRootPart.AssemblyLinearVelocity)
		repeat task.wait(0.1) until HumRootPart.AssemblyLinearVelocity.Magnitude <= 1 
		
		SlideContinuousTrack:Stop()
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.