Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Magnitude Between Two Parts?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

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

0
Thanks! Ftlicious 16 — 6y
Ad

Answer this question