generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Need help with damaging humanoid

Previous Thread :: Next Thread 
Raildex is not online. 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 is not online. Locard
Joined: 13 Apr 2014
Total Posts: 3516
08 Feb 2016 11:55 AM

So what's wrong with it?
Report Abuse
Raildex is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image