Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

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?

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

0

I believe the 5 is measuredn studs

This discussion is preserved as it was. New answers, comments, and votes are closed.