|
| 17 Feb 2012 11:50 AM |
So what I'm trying to do is I have a button, right? So if a car hits the button it prints "Car". If anything else hits it, it prints "Error". The script can tell if it's a car since the car has a vehicle seat. Here's my code could someone make it work and make it tidier?
function carwash(hit) local h = hit.Parent:findFirstChild("VehicleSeat") if h then local per = hit.Parent:findFirstChild("Humanoid") if not per then print("Coding goes here") else print("Error") end end end
script.Parent.Touched:connect(carwash) |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 17 Feb 2012 11:52 AM |
| if hit.Parent is nil then the event will be disconnected and the button won't work anymore. |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2012 11:55 AM |
| I don't get what your saying. :P |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 17 Feb 2012 11:57 AM |
1. A bullet hits your button. 2. The bullet has a script inside it which deletes the bullet on impact. 3. The button's script assumes the bullet has a parent (which isn't true in this case) 4. The function errors 5. Your button breaks |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2012 12:08 PM |
You my kind sir, make no sense. All I'm trying to do is make a carwash. The script drives the car if the car hits the sensor. I can do that easily. But if a a person or some other object hits the button it errors out and the script breaks. Nothing you've said has any relevance once so ever. :P
Bullets? FTW! |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 17 Feb 2012 05:35 PM |
| Thanks. I didn't use that exact code as that wouldn't work but I used the nil part and it works. :D |
|
|
| Report Abuse |
|
|