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

Making block detect what block is touching it?

Asked by 8 years ago

So im creating a game and im trying to think of a way to get a block to detect what block is touching it:

So for example:

Block 1 detects that block 2 is touching it so it spawns a car.

Another example: Block1 detects that block 3 is touching it so it spawns a monkey.

They are just examples, I don't want a full code I just want advice on what I would use, Would i use .Touched or something similar.

Thanks for help.

2 answers

Log in to vote
-1
Answered by 8 years ago

Well I would advise that you use the Touched Event of the block in order to detect what it is using and also you can use its perimeters to identify the Part that it touches something like this..

function detect(hit) -- Beginning a function
if hit and hit.Name == "Block1" then -- If statement to check for the name and if the object exists.
-- stuff
end -- end for if statement
end -- end for function.

script.Parent.Touched:connect(detect)  -- Connects function to event.

I hope I helped and thank you for reading this answer.

~~ KingLoneCat

0
Thak youso much for the help! :) Benmz41998 19 — 8y
0
No problem. KingLoneCat 2642 — 8y
Ad
Log in to vote
-1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

If you just want to know when an object touches a part, just once (Could stop touching the part at any time), then Touched is good for you. If you want to see if a part is currently touching a part, you'd need to toggle a variable, as well as using tthe 2 events Touched and TouchEnded.

Answer this question