Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Magnitude with HumanoidRootPart isn't working ?

The script is located in game.StarterGui

The script is a "LocalScript"

-- Variables

local distPart = game.Workspace.distPart
local humRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")



if (humRootPart - distPart).magnitude < 15 then
	
	print("The Player Is In Range Of The Object!")
	
end

Here's the error that i'm getting : Players.ZOOP1015.PlayerGui.LocalScript:8: attempt to perform arithmetic (sub) on Instance

3 comments

0

I think you need to define Position aswell.Like (humRootPart.Position - distPart.Position).Magnitude

0

Woah, that was a silly mistake that i did, thanks for the answer! How do i accept your answer on this website exactly, it doens't give me the option to do so.

0

Yeah you can't accept a comment as an answer

1 answer

✓ Accepted answer

Basically, You You need to check for the Positions of the both, that's how you use Position. To get the Vector3 Values eg of humRootPart and the distPart

-- Variables

local distPart = game.Workspace.distPart
local humRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")



if (humRootPart.Position - distPart.Position).magnitude < 15 then

    print("The Player Is In Range Of The Object!")

end

This discussion is preserved as it was. New answers, comments, and votes are closed.