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

Is it possible to detect when a player is near a brick or when a brick is near another brick?

Asked by 9 years ago

Hello, I just want to know if it's possible and what (function/snippet/concept/topic of lua) that I would use if I wanted to create something like this, basically I want you to point me towards a path that I can go to, to create this.

Is it possible to detect when a player is near a brick or when a brick is near another brick? What would I use to achieve this?

Please point me towards the right direction. Thank you!

1 answer

Log in to vote
1
Answered by
Damo999 182
9 years ago

Yes you could use magnitude here an example.

player = game.Players.LocalPlayer  --define player
part1 = game.Workspace.Part1 --the part you want to use to detect the player

while true do -- use a while loop to constantly check if the player is close
    wait()
    if(player.Character.Torso.Position - part1.Position).magnitude <=5 then -- this line takes your characters position and subtracts it from the parts position ad check to see if it is less than or equal to
        print("You are near me") -- prints when you are close enough to the part
    end
end

--to detect two bricks same concept instead of adding player just add  another part to the script
so it would look like this 

part1 = game.Workspace.Part1
part2 = game.Workspace.Part2

while true do 
    wait()
    if(part1.Position - part2.Position).magnitude <=5 then
        print("You are near me") 
    end
end

I hope this helps.

0
This seems like a great explanation. Thank you very much. However, if you can still reply then may I ask what it subtracts '5' by? The X axis or the Y axis? Arithmeticity 167 — 9y
0
Thank you and it doesn't matter if you come to the brick from the x,y, or z axis if you are close enough it will detect you Damo999 182 — 9y
0
I believe the 5 is measuredn studs Mystdar 352 — 9y
Ad

Answer this question