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

Brick Only Detection? No tutorials on YT

Asked by 6 years ago

I've been searching and searching for a brick only detection and there is none on YT (when players touch a brick nothing happens but when a brick touches a brick a script plays.) I have no idea if this is possible or if it's just a hard thing to do. Is it just a slight change like

function onTouched(Puck)

Or something?

Sorry no script because I have no idea. I'll try to figure out how the script works or maybe If I get a small piece of a script I may build up on it.

I'm a hockey fan so I'm trying to make a puck go into a goal and that'll activate scripts but when a player goes through the detector (aka. Inside the goal) no script will activate.

3 answers

Log in to vote
0
Answered by 6 years ago

Ok, so since you're wanting to do only a part that touches the goal, you have to specify some if statements.

script.Parent.Touched:Connect(function(Puck)

    if Puck.ClassName == "Part" or Puck.ClassName == "Union" or Puck.ClassName == "BasePart" then--Checks if the thing touching the goal is a part
        if Puck.Name == "Puck" then --Assuming your puck's name is named Puck, this checks if the thing touching the goal is named Puck.
    --Insert the script you wish to activate when the puck goes inside the goal

        end 
    end
end)

Place this script inside the goal part (not the model if it is a model, because Touched isnt a valid event of a model), with the goal part as the parent. Whenever something touches the goal part, this script runs, and it first checks if the thing touching the goal is some sort of part, then assuming your puck part is named Puck, then your script activates. If you'd like, at line 3 you can remove or Puck.ClassName == "Union" or Puck.ClassName == "BasePart", but I'd rather not, because if the puck wasn't a part, but instead a union of parts or a basepart, then this script wouldn't run how you would want it to.

0
"BasePart" isnt a classname, use or Puck:IsA("BasePart") the8bitdude11 358 — 6y
2
use if Puck:IsA("BasePart") instead of checking the classname User#23365 30 — 6y
0
and you dont need to check if it is a union or a part using :IsA("BasePart") the8bitdude11 358 — 6y
0
Puck.ClassName == "BasePart" worked... AwesomeGamer2223 105 — 6y
0
Ok so if it worked, then I just recommend according to these people that you just use .ClassName == "BasePart" or use :IsA("BasePart") ScrubSadmir 200 — 6y
Ad
Log in to vote
2
Answered by 6 years ago
Edited 6 years ago
script.Parent.Touched:Connect(function(Puck)
    if Puck:IsA("BasePart") then --Checks whether the instance hit is any type of part (E.g Mesh Part, Normal Part etc)
        --Script here
    end
end)
2
this looks like the best answer. RainbowGirlAmrita 2 — 6y
0
Thanks lol MaximumOverdriven 152 — 6y
Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

Explanation here.

function onTouched() -- We will make a function that includes all this code in it

end

script.Parent.Touched:Connect(onTouched) -- This is what actually runs the function.
--                ^      ^        ^
--                1      2        3

--  1. Detects for a touch
--  2. Connects it
--  3. Runs "OnTouched" Function

You are better off with script.Parent.Touched:Connect(function() sense using a function for touched is really old and impractical.

0
You realize that this helps 0% right? User#25115 0 — 6y
0
You realize that I don't care right? LoganboyInCO 150 — 6y
0
You realize that makes anything that touches it start the function right? AwesomeGamer2223 105 — 6y

Answer this question