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

Why is it not detecting distance?

Asked by
emite1000 335 Moderation Voter
10 years ago

A simple version of my script (provided by ShawnyG in my last question).

Why does this not work:

torso = game.Players.LocalPlayer.Character.Torso
part2 = game.Workspace.Part2

if (torso.Position - part2.Position).magnitude >= 40) then
    print('It is 40 studs away!!!')
end

The script is enabled. There is a LocalScript in the StarterGui. There is a part named "Part2" in the Workspace. There is no output. I'm stumped.

**UPDATE: **I added print("The script is responding") at line 3, but nothing even prints. I'm even more confused now. This is in a LocalScript in the Workspace.

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

You have an unmatched parenthesis:

if (torso.Position - part2.Position).magnitude >= 40) then
--                                                  ^

Remove it.

This is why nothing printed even at the beginning-- Lua cannot do anything at all if you have a syntax error.

0
Ah, my problem was instead of removing that parenthesis, I had added a second one behind it (in an attempt to close the other one pointing to the right). Thank you very much, big problems like these always seem to be caused by such a small problem. emite1000 335 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

From the wiki: "In order for a LocalScript to function, it must be placed within one of three areas:

-In a player's Backpack (can be indirectly, through a Tool or HopperBin) -In a player's character model -In a player's PlayerGui"

LocalScripts do not run in the workspace, move it to an appropriate place for it to run

0
Studio crashes whenever I put it in the player though. emite1000 335 — 10y
0
There's no reason studio should be crashing. Is this the whole script? Make sure if this is inside a while loop to include a wait(), that is most likely your problem. ColdSmoke 55 — 10y

Answer this question