|
| 26 Jun 2016 05:57 AM |
I am trying to implement a simple system in which a specific model or building holds a value which determines how many times it can be hit by a specific projectile (In this case "Rock") before activating a destruction script. So far I have had trouble getting a script to subtract the "health" value as soon as a projectile (Rock) hits the block the script and value it is inside in. The script looks like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ local health = script.Parent.Health.Value
function onTouched(part) local h = part.Parent:findFirstChild("Rock") if h~=nil then wait() health = health - 1 end end
script.Parent.Touched:connect(onTouched) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When tested the value appeared unchanged. When this failed I tried this to check out if a value can indeed be subtracted:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ local health = script.Parent.Health.Value
while true do wait(1) heath = health - 1 print(health) end ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The output shows that the subtraction is working. So I have a question. Why cant a simple value to be subtracted as soon as an object hits the trigger? Am I doing something wrong? |
|
|
| Report Abuse |
|
|
| 26 Jun 2016 06:29 AM |
Also you can take a look at this for some context to what am I doing:
http://www.roblox.com/games/13093174/Pompeii-destruction-test |
|
|
| Report Abuse |
|