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

A part being able to detect the difference between a player and another part. Any help?

Asked by 10 years ago

I have built a car with parts that act as "airbags". When something hits the "trigger" that's under the hood, the "airbags" then turn visible and cancollide is set to true. At the same time, the throttle is also set to "0" and high friction "brakes" under the car are then activated.

My question is, how do I get the "trigger" ,that the script below is in, to tell the difference between a player and a part. I don't want anything to happen when a player touches the "trigger" but when a part hits it, I want the script to run.

This is what I have. Yes its long and super basic.. sorry about that..

function onTouched(hit)
    script.Parent.Parent.Part1.CanCollide = true
    script.Parent.Parent.Part2.CanCollide = true
    script.Parent.Parent.Part3.CanCollide = true
    script.Parent.Parent.Part4.CanCollide = true
    script.Parent.Parent.DriverSeat.Throttle = 0
    script.Parent.Parent.Airbag1.Transparency = 0
    script.Parent.Parent.Airbag2.Transparency = 0
    script.Parent.Parent.Airbag3.Transparency = 0
    script.Parent.Parent.Airbag4.Transparency = 0
    script.Parent.Parent.Airbag1.CanCollide = true
    script.Parent.Parent.Airbag2.CanCollide = true
    script.Parent.Parent.Airbag3.CanCollide = true
    script.Parent.Parent.Airbag4.CanCollide = true
end 
script.Parent.Touched:connect(onTouched)

Any help on this would be very helpful to me and I would be very grateful, thanks :)

3 answers

Log in to vote
0
Answered by 10 years ago

You can use :FindFirstChild("Humanoid") to see if what has touched it has a humanoid.

Ad
Log in to vote
-1
Answered by
yurhomi10 192
10 years ago
distance = (part.Position - player.Torso.Position).magnitude
while magnitude do
if magnitude <= 100 then
print(magnitude)
else
print("Not close enough")
end
end
Log in to vote
-1
Answered by 10 years ago

I originally had this problem with trains and railroad crossings. I use triggers on the rails to activate the signals, however people could have walked over a trigger and also set them off. Here is what I came up with.

local debounce = false

function onTouched(part)

    if debounce == false then
if part.Name == "Wheel" then
        debounce = true

[In here is where all of the signal codes are, you'll place your airbag stuff here.]

        debounce = false
    end
    end

end

script.Parent.Touched:connect(onTouched)

(The line "local debounce = false" at the top is line 1) Above, you'll notice that a part named Wheel has to hit the trigger, which is the brick this script is inside of. You may change the name Wheel to whatever the name of the part is that you want to trigger the airbag. If you set it to be triggered by a part named Part, it'll work with parts named Part. This lets parts with different names, and people, to have no effect on it. Also note that in putting the name, as you see my part name Wheel has a capitol W, caps count. So a part named wheel would NOT activate it unless it had a capitol W, like Wheel. To sum up the above, if you put in the name "Part" to substitute for my name "Wheel" then only parts with the name Part (capitol P) would trigger it. People or other parts would not. Hope this helped!

0
Never mind, I got it to work. Sorry about that.. But thank you very much :) devon1029 0 — 10y
0
No problem. I actually so far have done nothing but answer people's questions. That's mainly why I joined, was to help people new to scripting. And who downvoted this? Now I have a -1 rep. :/ DieselElevatorsRBLX 0 — 10y

Answer this question