|
| 24 Dec 2013 12:08 PM |
Hello!
Im curious as to how I would reference another value in a model from a part that touches that model?
Im trying to make a ship Damage system and Ive set it up so that if a Part named "Tip" hits that Model then the Value in that hit model minus 2 in the value.
Any idea how I would reference that value in the said model that is hit? |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:17 PM |
so you have a part that hits a model, and you want the model.Health.Value to decrease?
Tip.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Health") t hen hit.Parent.Health.Value = hit.Parent.Health.Value-2 end end)
Like that? |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:18 PM |
Ooo, Lemme try that. I had a feeling it was that findfirstchild but I wasent sure.
Thank you!
|
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:24 PM |
Im getting an Error from it. Attempt to indx global "Tip" a nil value.
|
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:26 PM |
| where are you putting the script? |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:28 PM |
in the Part named "Tip" Its in a model, in a model.
script>Tip>Model>Model |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:38 PM |
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Health") then hit.Parent.Health.Value = hit.Parent.Health.Value-2 end end)
Try that then. This is assuming the value you want to decrease is called Health, and is a number or int value. |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:53 PM |
| It works in a sense my game didnt lag out but the value in the other model dosent minus either. |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 12:56 PM |
Is this the correct hierarchy for the model that is hit:
model -Health -Part -Part -Part -Part -Part -Part -Part -Part
Where Health is a number value, and is named 'Health', and Part is the part that is hit.
|
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 01:04 PM |
Its Model Integrity(IntValue) Helm Hull Log Log Etc... Tip |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 01:06 PM |
This then:
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Integrity") then hit.Parent.Integrity.Value = hit.Parent.Integrity.Value-2 end end)
|
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 01:08 PM |
I tried that. Didnt work. I even added
Hull = script.Parent.Parent.Parent
script.Parent.Touched:connect(function(hit) if hit.Name == "Log" then if hit.Parent:FindFirstChild("Integrity") then hit.Parent.Integrity.Value = hit.Parent.Integrity.Value - 1 end end end) |
|
|
| Report Abuse |
|
|
CrniOrao
|
  |
| Joined: 12 Oct 2008 |
| Total Posts: 2274 |
|
|
| 24 Dec 2013 01:12 PM |
Try showing the models like this:
-Model --Model ---Model ----Part ----Part ----Part ----^Script ----Part ----^Script -----Model ------Part -------^Script
Like this, if you see what I mean, you probably showed it wrong and the Parenting is wrong quite much! |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2013 01:15 PM |
-Model --IntValue --Model --Model ---Log ---Log ---50 Log's Later ---Tip ----^script
should just be
script.Parent.Parent.Parent |
|
|
| Report Abuse |
|
|
CrniOrao
|
  |
| Joined: 12 Oct 2008 |
| Total Posts: 2274 |
|
|
| 24 Dec 2013 01:18 PM |
integ = hit.Parent.Parent.Parent.Integrity
script.Parent.Touched:connect(function(hit) if hit.Name == "Log" then if hit.Parent:FindFirstChild("Integrity") then integ.Value = integ.Value - 1 end end end) |
|
|
| Report Abuse |
|
|