Detect when player falls from a tall height efficiently in server side?

I wanted to make a script that resets the player when they fall from a certain height.
It looks like this:

hum.StateChanged:Connect(function(OldState, NewState)
	if NewState == Enum.HumanoidStateType.Landed then
		local Height = -root.Velocity.Y
		if Height >= 10 then
			-- Run code
		end
	end
end)

But, this is a localscript and I heard that exploiters can change values in localscripts, meaning they can change the height to a really high number so they will never reset. Is this true?

If it is, what is the most efficient way to detect when player falls from a tall height server side for every player? Thanks.

1 Like

your script should work fine if you add playeradded and characteradded into it but thought this would be a better way of doing this

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		local Hum, Root = Char:WaitForChild("Humanoid"), Char:WaitForChild("HumanoidRootPart")
		local OldPos = Vector3.new()
		
		Hum.StateChanged:Connect(function(Old, New)
			if (New == Enum.HumanoidStateType.Freefall) then 
				OldPos = Root.Position
			elseif (Old == Enum.HumanoidStateType.Freefall) then 
				local Dist = (-(Root.Position-OldPos).Y)
				
				if (Dist >= 15) then 
					print("damage")
				end
			end
		end)
	end)
end)

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