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 » Scripting Helpers
Home Search
 

Re: How would I make this explode?

Previous Thread :: Next Thread 
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
08 Dec 2013 08:29 PM
I know it would go something like this, but I want it to only explode after it's been hit four times.. How would I do that? This is what I have.

local s = script.Parent:GetChildren()
s.Touched:connect(function(hit)
if hit.Name=="Bullet" then
local e = Instance.new("Explosion")
e.Parent = script.Parent.Head
wait(.1)
script.Parent:BreakJoints()


If you're wondering, there is a humanoid and a head inside the model. What I don't understand is how to make it get hit four times until it explodes.

Strength, Honor, Glory. Hail Puternic Imperium!
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
08 Dec 2013 08:30 PM
local s = script.Parent:GetChildren()
local hit = 0;

s.Touched:connect(function(hit)
     if hit.Name=="Bullet" then
          if hit < 4 then
               hit = hit + 1
               return
          elseif hit == 3 then
               hit = 0
               local e = Instance.new("Explosion")
               e.Parent = script.Parent.Head
               wait(.1)
               script.Parent:BreakJoints()
          end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
08 Dec 2013 08:33 PM
Make each bullet do 25 dmg, and then

script.Parent.Humanoid.Died:connect(function() exp=Instance.new("Explosion", script.Parent.Head)
exp.Position = script.Parent.Head.Position
end)
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
08 Dec 2013 08:33 PM
21:31:10.816 - Workspace.Model.ExpScript.Script:4: attempt to index field 'Touched' (a nil value)
Line 4.

I think it's because Touched isn't a property of some of the things that I have in the model. How will I make it only touched for the touchable parts?

Strength, Honor, Glory. Hail Puternic Imperium!
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
08 Dec 2013 08:35 PM
Ah, I just realized you did it completely wrong.

local s = script.Parent:GetChildren()
local hit = 0;

for i,v in pairs(s) do
if v:IsA([==[BasePart]==]) then
v.Touched:connect(function(hit)
if hit.Name=="Bullet" then
if hit < 4 then
hit = hit + 1
return
elseif hit == 3 then
hit = 0
local e = Instance.new("Explosion")
e.Parent = script.Parent.Head
wait(.1)
script.Parent:BreakJoints()
end
-- all your ends here
end
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
08 Dec 2013 08:38 PM
No errors, but it doesn't seem to work.

Strength, Honor, Glory. Hail Puternic Imperium!
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
08 Dec 2013 08:42 PM
"if hit < 4 then"

Change that to < 3
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
08 Dec 2013 08:44 PM
Workspace.Model.Model.ExpScript:8: attempt to compare userdata with number
21:42:29.235 - Script 'Workspace.Model.Model.ExpScript', Line 8
21:42:29.236 - stack end

Strength, Honor, Glory. Hail Puternic Imperium!
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
08 Dec 2013 08:45 PM
mmm

local s = script.Parent:GetChildren()
local hit_ = 0;

for i,v in pairs(s) do
if v:IsA([==[BasePart]==]) then
v.Touched:connect(function(hit)
if hit.Name=="Bullet" then
if hit_ < 4 then
hit_ = hit_ + 1
return
elseif hit_ == 4 then
hit_ = 0
local e = Instance.new("Explosion")
e.Parent = script.Parent.Head
wait(.1)
script.Parent:BreakJoints()
end
-- all your ends here
end
Report Abuse
Adam2090 is not online. Adam2090
Joined: 19 Jul 2010
Total Posts: 889
08 Dec 2013 08:48 PM
Now it doesn't do anything.

Strength, Honor, Glory. Hail Puternic Imperium!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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