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

Magnitude Between Two Parts?

I am trying to print the rounded verision of the magnitude between two parts. When I run this script, I get an error saying 'attempt to index a nil value'. Can someone help me with this?

while wait(2) do
	print(tonumber(game.workspace.Part1.Position - game.workspace.Part2.Position).magnitude)

end

1 answer

✓ Accepted answer

Dont use print(tonumber(...).magnitude) only use print((...).magnitude).

for use tonumber you need to use: print(tonumber((...).magnitude)) not print(tonumber(...).magnitude)

and you can use workspace or game.Workspace or game:GetService("Workspace"). but do not use game.workspace

in use magnitude you need to use the parentheses: (...).magnitude Never forget that when using magnitude

Why you get error? you used tonumber(...).magnitude you need to use tonumber((...).magnitude)

Here is fixed script:

while wait(2) do
    print(tonumber((workspace.Part1.Position - workspace.Part2.Position).magnitude))
end

Hope it helped :)

1 comment

0

Thanks!

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