How do i more quickly detect landng?

I made this:

but my issue is that it takes a few MS before it actually squishes the character. Can i make this so it squishes as soon as i hit the ground? Also i have some reliability issues with it where sometimes it just doesnt work.

Heres how i am detecting right now:

script.Parent:WaitForChild("HumanoidRootPart").Touched:Connect(function()
	local A = math.abs(script.Parent.HumanoidRootPart.AssemblyLinearVelocity.Y/200)
	print(A)
	if A > 0.1 then
		Squish(script.Parent, 1-A, false)
	end
end)

(Parented to the character)

Shoot a raycast downwards from the character if they aren’t touching the ground. That way you can call the squish function before the player hits the ground. You can increase the distance of the raycast to whatever you like, higher = more latency.

local character = script.Parent
local root = character.HumanoidRootPart

local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude

local result = workspace:Raycast(root.Position, -Vector3.yAxis * 4, params)
if result then
	local A = math.abs(root.AssemblyLinearVelocity.Y/200)
	Squish(character, 1-A, false)
end

do i just put the last 5 lines in a while true loop and break it once you hit the ground?

It would be better if you put it in a Heartbeat and check when the player is accelerating downwards.

local character = script.Parent
local root = character.HumanoidRootPart

local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude

local squishDebounce = false
RunService.Heartbeat:Connect(function(dt: number): ()
	if root.AssemblyLinearVelocity.Y < 0 and not squishDebounce then
		local result = workspace:Raycast(root.Position, -Vector3.yAxis * 4, params)
		
		if result then
			squishDebounce = true
			task.delay(0.5, function() squishDebounce = false end)
			
			local A = math.abs(root.AssemblyLinearVelocity.Y/200)
			Squish(character, 1-A, false)
		end
	end
end)

This way you don’t have to use while loops.

why not use humanoid.StateChanged? (even if its serversided, pretty sure it would be smoother)

Yeah, humanoid.StateChanged would probably be a better route than sticking it in a Heartbeat. You just have less latency control.

local humanoid = script.Parent:WaitForChild("Humanoid") :: Humanoid
local rootPart = humanoid.RootPart

humanoid.StateChanged:Connect(function(_, newState: Enum.HumanoidStateType)
	if newState ~= Enum.HumanoidStateType.Landed then
		return
	end

	local velocity = rootPart.AssemblyLinearVelocity.Y
	local impactForce = math.abs(velocity / 200)

	if impactForce > 0.1 then
		Squish(script.Parent, 1 - impactForce, false)
	end
end)

cannot really test it out cause i dont have access to the Squish function

have you tried humanoid.FloorMaterial?