So, i have this script, but i want it just to check the Y
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Object = game.Workspace:WaitForChild("EnemyPart")
local Distance = (Object.Position - player.Character.HumanoidRootPart.Position).Magnitude
print(Distance)
ty!
You need to subtract the Y positions of the player’s character and the object.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Object = game.Workspace:WaitForChild("EnemyPart")
-- Get the Y positions of the object and the player
local objectY = Object.Position.Y
local playerY = player.Character.HumanoidRootPart.Position.Y
-- Calculate the Y distance
local yDistance = math.abs(objectY - playerY)
print(yDistance)
(The math.abs
function ensures the distance is always a positive value.)