yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 01:58 PM |
I want the gun to set the player's health to 1 at the first hit, then to 0 at the second. Yet when I test it out, it just insta-kills the player.
Here's the script:
bullet.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent.Name ~= "Workspace" then local h = hit.Parent:FindFirstChild'Humanoid' if h.Health >1 then h.Health = "1" else h.Health = "0" end end end)
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 01:59 PM |
Or at least, the part of the script that's responsible for the health.
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2015 01:59 PM |
| Add a debounce. Also, raycasting is much better for this. |
|
|
| Report Abuse |
|
|
71428
|
  |
| Joined: 06 Aug 2015 |
| Total Posts: 339 |
|
|
| 16 Aug 2015 02:01 PM |
if h.Health >1 then h.Health = "1" else h.Health = "0" end
What's up with the quotes. Remove them.
if h.Health >1 then h.Health = 1 else h.Health = 0 end |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 02:08 PM |
Still not working. Here's the part of the script now:
local damageTaken = false bullet.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent.Name ~= "Workspace" then local h = hit.Parent:FindFirstChild'Humanoid' if not damageTaken then if h.Health >1 then damageTaken = true h.Health = "1" damageTaken = false else damageTaken = true h.Health = "0" damageTaken = false end end end end)
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 02:10 PM |
@714
Makes no difference.
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 02:18 PM |
Anyone?
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2015 02:24 PM |
what u mean "at second time"? if u mean the 2nd bullet that hits the player then, it's not as easy as checking the health, u have to somehow mark the Humanoid to let other bullets know he/she has be hit
"My Life is going Good... but..." |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 02:35 PM |
I made the script to check if the humanoid's health is at 1 or not, so it can set it to 0 or 1.
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2015 03:17 PM |
well then it should work :P "if Health > 1 then Health = 1 else Health = 0" meaning that if the health is bigger than 1 i then it's set to 1 otherwise it's set to 0... what's not working??? o.O
"My Life is going Good... but..." |
|
|
| Report Abuse |
|
|
71428
|
  |
| Joined: 06 Aug 2015 |
| Total Posts: 339 |
|
|
| 16 Aug 2015 05:27 PM |
scriptEnabled = true bullet.Touched:connect(function(hit) if hit ~= nil then if not scriptEnabled then return end scriptEnabled = false local h = hit.Parent:FindFirstChild("Humanoid") if h.Health == 1 then h.Health = 0 elseif h.Health > 1 then h.Health = 1 wait(1) end scriptEnabled = true end end)
You need a debounce with waiting time because the function executes several times while the bullet travels through the player. Assuming it does. How fast is the bullet? You need to wait until it leaves the player's body. So you can find the magnitude of both the part it hit and the bullet and if it is a certain distance away it has left the body. |
|
|
| Report Abuse |
|
|
|
| 16 Aug 2015 05:49 PM |
Use raycasting, this has been da thang since like 09'
Women are like fine wine, I can't get their tops off |
|
|
| Report Abuse |
|
|
yeox769
|
  |
| Joined: 21 Jun 2010 |
| Total Posts: 8907 |
|
|
| 16 Aug 2015 10:22 PM |
Thanks, 714!
.:[Transmission end.]:. |
|
|
| Report Abuse |
|
|