How do I detect how high a jump was?

A quick question here. How would I be able to detect how high a players jump was? I’m curious as I am trying to make my player jump and when they land have a little bit of dust particle to make it look nice.

2 Likes

All players jump the same height? Add a humanoid to starterplayer and you can adjust jumppower from there.

But like how would I know how high the jump was. I’m saying if you were on a tall block and jumped off of it, how would I detect that the player jumped from that height.

Oh I see. For that you can use the FreeFall state and use deltaTime to see how long it took. The longer the height, the longer the fall.

local player = game.Players.LocalPlayer
player.CharacterAdded:wait()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

humanoid.FreeFalling:Connect(function(active)
	if active then
		local oldTime, newTime = tick(), tick()
		while wait() do
			newTime = tick()
			if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			else
				break
			end
		end
		local fallTime = (newTime - oldTime) * 1000
		print("Character free fell for", math.round(fallTime), "milliseconds.")
	end
end)

FreeFalling or FallingDown will work, the above makes use of the FreeFalling state.

I’m pretty sure the answer above is more accurate but I had written it already

----- Services -----

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

----- Variables -----

local Player = Players.LocalPlayer
local Character = Player.Character
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")

local StartPosition

----- Code -----

local function Jumped() --Player jumped
	StartPosition = RootPart.Position
end

local function Landed() --Player landed
	local EndPosition = RootPart.Position
	if StartPosition then --If startposition isn't nil
		local JumpMagnitude = (StartPosition - EndPosition).Magnitude
		local JumpDistance = math.round(JumpMagnitude)
		print("The distance of your jump was " .. JumpDistance .. "Studs")
	end
end

UserInputService.JumpRequest:connect(Jumped)
Humanoid.StateChanged:Connect(function(Old, New)
	if New == Enum.HumanoidStateType.Landed then
		Landed()
	end
end)