Answered by
6 years ago Edited 6 years ago
What I think you are trying to do is when the player's UpperTorso gets within the radius of radius
which is 10, then print "Human Nearby". Your script runs only once when the game starts and since distance is not <= radius the if
doesn't run.
You should try using a while
loop for this:
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character |
04 | local part 1 = char:WaitForChild( "UpperTorso" ) |
05 | local part 2 = game.Workspace.Part |
10 | local distance = (part 1. Position - part 2. Position).magnitude |
12 | if distance < = radius then |
or if you want it to only print once:
01 | local player = game.Players.LocalPlayer |
02 | local char = player.Character |
04 | local part 1 = char:WaitForChild( "UpperTorso" ) |
05 | local part 2 = game.Workspace.Part |
11 | local distance = (part 1. Position - part 2. Position).magnitude |
13 | if debounce and distance < = radius then |
16 | else not debounce and distance > radius then |
The while loop will keep running and check if distance <= radius
instead of only checking once.
I have not tested it so I'm definitely not 100% sure it'll work.