|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 24 Jan 2011 |
| Total Posts: 1027 |
|
|
| 17 May 2014 01:50 PM |
| There's no touched event for explosions, youssef |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
|
| 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
|
  |
| 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
|
  |
| Joined: 22 Jan 2011 |
| Total Posts: 1745 |
|
|
| 17 May 2014 01:54 PM |
| Nevermind, didn't see the 2nd function. |
|
|
| Report Abuse |
|
|
|
| 17 May 2014 02:00 PM |
I got it to work by adding: if not hitPlayer then return end
Thanks CERE4LKILLER |
|
|
| Report Abuse |
|
|