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
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 :)