Raildex
|
  |
| Joined: 06 Dec 2009 |
| Total Posts: 934 |
|
|
| 08 Feb 2016 11:52 AM |
Im testing out a prototype for a tower defence game and the way I have it right now it just straight up damages the humanoid, I need to make it so that it damages an enemy only when the bullet hits it.
while true do --====Rest of the script [extra features]=====----
if target then print("true target") local mag = (script.Parent.Position - target.Head.Position).magnitude print(mag) if (mag <= range) then print("in range") for i = 0, burstNum do local bullet = Instance.new('Part', game.Workspace) game.Debris:AddItem(bullet, 2) bullet.BrickColor = BrickColor.new("Really red") bullet.Transparency = .4 bullet.CanCollide = false bullet.Size = Vector3.new(.3,.3, 1) bullet.CFrame = core.CFrame bullet.CFrame = CFrame.new(bullet.Position,target.Head.Position) local v = Instance.new("BodyVelocity", bullet) v.velocity = bullet.CFrame.lookVector * 90 v.maxForce = Vector3.new(math.huge, math.huge, math.huge) v.P = bulletSpeed
local humanoid = target:FindFirstChild("Humanoid") if humanoid then humanoid.Health = humanoid.Health - damage end wait(.05) end else found = false end wait(1) end |
|
|
| Report Abuse |
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
| |
Raildex
|
  |
| Joined: 06 Dec 2009 |
| Total Posts: 934 |
|
|
| 08 Feb 2016 11:57 AM |
| as soon as the bullet is created the humanoid takes damge. I need it so that the humanoid takes damage when the bullet comes into contact with it |
|
|
| Report Abuse |
|
Locard
|
  |
| Joined: 13 Apr 2014 |
| Total Posts: 3516 |
|
|
| 08 Feb 2016 12:02 PM |
Oh.
You're not giving that specific task to the bullet but you are giving it to the loop. You want the humanoid to take damage from the bullet? Apply the Touched event.
bullet.Touched:connect(function(obj)
local humanoid = obj.Parent:FindFirstChild'Humanoid' or obj.Parent.Parent:FindFirstChild'Humanoid'
if humanoid then humanoid.Health = humanoid.Health - damage end bullet:destroy() end) |
|
|
| Report Abuse |
|