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: Explosion Hit Event help

Previous Thread :: Next Thread 
StrikerBOY606 is not online. StrikerBOY606
Joined: 25 Oct 2010
Total Posts: 747
17 May 2014 01:44 PM
I'm trying to script it so that the explosion will ignore all the players that are on the same team as the person who set the explosion off, but if they're on the other team it will kill them.

[ Script]

local explosion = Instance.new("Explosion",missile)
explosion.Position = missile.Position
explosion.BlastPressure = 0
explosion.BlastRadius = 10
explosion.Hit:connect(function(hitPart)
if (hitPart.Parent:FindFirstChild("Humanoid")) then
local hitPlayer = game.Players:GetPlayerFromCharacter(hitPart.Parent) --The problem is here!
local player = game.Players:GetPlayerFromCharacter(char)
if (p.TeamColor ~= player.TeamColor) then
hitPlayer.Parent.Humanoid:TakeDamage(100)
end
end
end)

[Output]

Workspace.Player1.MortarMissile.Script:59: attempt to index local 'hitPlayer' (a nil value)
Report Abuse
youssef04 is not online. youssef04
Joined: 22 Jan 2011
Total Posts: 1745
17 May 2014 01:47 PM
Full script?
You need a touched function.
So put this at top:
script.Parent.Touched:connect(function Touch(hitPart)
and this at bottom:
end)
Report Abuse
Perci1 is not online. Perci1
Joined: 24 Jan 2011
Total Posts: 1027
17 May 2014 01:49 PM
This may help. I don't usually use explosions.

http://wiki.roblox.com/index.php?title=Hit_(Event)
Report Abuse
Perci1 is not online. Perci1
Joined: 24 Jan 2011
Total Posts: 1027
17 May 2014 01:50 PM
There's no touched event for explosions, youssef
Report Abuse
CERE4LKILLER is not online. CERE4LKILLER
Joined: 04 Dec 2011
Total Posts: 138
17 May 2014 01:51 PM
Try putting this after the problem line. It won't attempt to continue if it can't find hitPlayer
if not hitPlayer then return end

PM me if this doesn't work. I use a nearly identical method in all of my .Touched functions and probably wont be on the forum for too much longer
Report Abuse
CERE4LKILLER is not online. CERE4LKILLER
Joined: 04 Dec 2011
Total Posts: 138
17 May 2014 01:51 PM
or listen to perci
Report Abuse
StrikerBOY606 is not online. StrikerBOY606
Joined: 25 Oct 2010
Total Posts: 747
17 May 2014 01:52 PM
I do already have a touched event

FULL SCRIPT

local missile = script.Parent
local sound = missile.ExplosionSound

missile.Touched:connect(function(hit)
local char = missile.Parent
if (hit) then
missile.Anchored = true
missile.Transparency = 1
local explosion = Instance.new("Explosion",missile)
explosion.Position = missile.Position
explosion.BlastPressure = 0
explosion.BlastRadius = 10
explosion.Hit:connect(function(hitPart)
if (hitPart.Parent:FindFirstChild("Humanoid")) then
local hitPlayer = game.Players:GetPlayerFromCharacter(hitPart.Parent)
local player = game.Players:GetPlayerFromCharacter(char)
if (hitPlayer.TeamColor ~= player.TeamColor) then
hitPlayer.Parent.Humanoid:TakeDamage(100)
end
end
end)
sound:Play()
wait(1.5)
missile:Destroy()
end
end)
Report Abuse
youssef04 is not online. youssef04
Joined: 22 Jan 2011
Total Posts: 1745
17 May 2014 01:53 PM
hitPart...
Remove the Part, and keep it as hit.
Report Abuse
youssef04 is not online. youssef04
Joined: 22 Jan 2011
Total Posts: 1745
17 May 2014 01:54 PM
Nevermind, didn't see the 2nd function.
Report Abuse
StrikerBOY606 is not online. StrikerBOY606
Joined: 25 Oct 2010
Total Posts: 747
17 May 2014 02:00 PM
I got it to work by adding: if not hitPlayer then return end

Thanks CERE4LKILLER
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