Confused with magnitude

Hey, so I tried fixing my dialogue with magnitude which worked but…


So where the red circle is that the part that checks how far the player is from the cave but when you’re at the blue point on the trail the dialogue comes back.

Here’s the script:
runService.RenderStepped:Connect(function()
if (player.Character.Head.Position).Magnitude >= (otherPart.Position).Magnitude then
dialog.Visible = false
else
dialog.Visible = true
end
end)

Thanks!

Sorry, can you format your script in the post for easier reading using code tags?

Also, you seem to be using the magnitude of a vector incorrectly. The distance is as such

local distance = (head.Position - part.Position).magnitude

And you’d check that with an if statement for a specific distance. Such as 10 or something.

2 Likes

Since you’re checking the distance from the player’s head, might I suggest using DistanceFromCharacter? This is because this built-in function calculates the distance from the player’s head already.

All you’ll do is pass it into the function such as player:DistanceFromCharacter(otherPart.Position) and it will return a number. You can check if it is within the distance that you want.

1 Like