im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
|
| 28 May 2013 01:31 AM |
How can I detect if a certain part (With a special name) touches another part with a special name. For example if I had a part called "Wheel", and a part called "Spike", when Spike touches Wheel, it executes a script. How can I do this? Already had a failed attempt at the script using a key card script.
|
|
|
| Report Abuse |
|
|
gamert7
|
  |
| Joined: 18 Nov 2008 |
| Total Posts: 4986 |
|
|
| 28 May 2013 01:48 AM |
-- Touched function with 'hit' in parentheses. local part = hit.Parent:FindFirstChild("Spike") if part~= nil then -- stuff
end end -- connection line. |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 28 May 2013 01:54 AM |
Put this in the wheel
script.Parent.Touched:connect(hit) if hit.Name == "Spike" then --execute whatever code u want end end) |
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
|
| 28 May 2013 05:16 AM |
gamert, I have this now, but it doesnt seem to work, I cant seem to figure out why,
function onTouched(hit) local part = hit.Parent:FindFirstChild("Spike") if part~= nil then script.Parent:Remove() end end
connection = hit.Touched:connect(onTouched)
|
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
| |
|
|
| 28 May 2013 06:26 AM |
script.Parent.Touched:connect(hit) if hit.Name==whatever then hit:Remove()
end |
|
|
| Report Abuse |
|
|
|
| 28 May 2013 06:28 AM |
:connect(function(hit)
end)* |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 28 May 2013 11:28 AM |
@Gamer's code won't work for you.
Try mine.
Need more help? Feel free to PM me :) |
|
|
| Report Abuse |
|
|
gamert7
|
  |
| Joined: 18 Nov 2008 |
| Total Posts: 4986 |
|
|
| 28 May 2013 01:10 PM |
| Arkose is correct I should have used hit.Name |
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
|
| 29 May 2013 06:30 AM |
Okay Arkose.. when Spike hits the part, I get this error:
attempt to call a nil value |
|
|
| Report Abuse |
|
|
|
| 29 May 2013 06:45 AM |
@Im2 You got that from output right? That is because script. is a nil value unless you make it a variable in your command.
Try putting this extra line in the code: print("The Spike Destroyed the Wheel!")
So, when your Wheel hits the spike, it should print to output "The Spike Destroyed the Wheel!" |
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
|
| 29 May 2013 04:11 PM |
| But! The spike does not pop the wheel in the script. Which is what it is supposed to do. |
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
| |
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
| |
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
| |
|
|
| 30 May 2013 09:43 PM |
This should go in the spike just for clarification. If it doesn't work then PM me.
function onTouched(hit) if hit.Name == "Wheel" then -- You can change the name in the quotation marks hit:remove() -- This deletes the wheel if it is hit with the spike end end
script.Parent.Touched:connect(onTouched)
|
|
|
| Report Abuse |
|
|
|
| 30 May 2013 09:52 PM |
Straight, simple answer here: In Spike put this
script.Parent.Touched:connect(function(hit) if hit.Parent.Name == "Wheel" then --Whatever you want to do end end) |
|
|
| Report Abuse |
|
|
im2awsm
|
  |
| Joined: 25 Aug 2010 |
| Total Posts: 2295 |
|
|
| 30 May 2013 10:38 PM |
| Thanks guys! Finally got it working!! |
|
|
| Report Abuse |
|
|