|
| 01 Jan 2014 06:14 PM |
local damage = math.random(4,15) function onTouched(hit) local human = hit.Parent:FindFirstChild("Humanoid") if (human == nil) then if hit.Parent.Locked == false then hit:BreakJoints() elseif hit.Parent.Locked == true then elseif (human ~= nil) then if human.Parent.Name == script.Parent.Owner.Value then elseif human.Parent.Name ~= script.Parent.Owner.Value then if hit.Parent.Name == Head then human.Health = human.Health - damage*2 elseif hit.Parent.Name ~= Head then human.Health = human.Health - damage end end end end connection = script.Parent.Touched:connect(onTouched) end
|
|
|
| Report Abuse |
|
|
| |
|
|
| 01 Jan 2014 06:36 PM |
I'm not a professional, I just started, but from what I see, I think the problem is within the "if"/"elseif".
I can't really explain. I'm a noob. Basically, wait around for someone better to come. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 01 Jan 2014 06:45 PM |
local damage = math.random(4,15) function onTouched(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then human.Health = human.Health-damage end end script.Parent.Touched:connect(onTouched) This will probably kill a player because touchéd event runs loads - someone add in denounce |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2014 07:16 PM |
Smiley's works, i tried editing it to making it so if it's not a human, it break joints..
local damage = math.random(4,15) function onTouched(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then if hit.Parent == Head then human.Health = human.Health-damage*2 else human.Health = human.Health-damage end end if not human then hit.Parent:BreakJoints() end end script.Parent.Touched:connect(onTouched)
Failed attempt btw... |
|
|
| Report Abuse |
|
|
| |
|
| |
|
lolb3
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 2268 |
|
|
| 01 Jan 2014 07:30 PM |
function onTouched(hit) local human = hit.Parent:FindFirstChild("Humanoid") if (human == nil) then if hit.Parent.Locked == false then hit:BreakJoints() elseif hit.Parent.Locked == true then if (human ~= nil) then if human.Parent.Name == script.Parent.Owner.Value then if human.Parent.Name ~= script.Parent.Owner.Value then if hit.Parent.Name == "Head" then human.Health = human.Health - math.random(4,15)*2 else human.Health = human.Health - math.random(4,15) end end end end end end end
connection = script.Parent.Touched:connect(onTouched(touch))
way to many elseifs please research if statements on the wiki |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2014 07:49 PM |
lolb3, that one gave me this error..
Workspace.Part.DamageScript:2: attempt to index local 'hit' (a nil value) |
|
|
| Report Abuse |
|
|
Avner
|
  |
| Joined: 30 Nov 2007 |
| Total Posts: 3390 |
|
| |
|
| |
|
| |
|
|
| 01 Jan 2014 09:17 PM |
| Uhhg.. how is "hit" a nil value??? |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 02 Jan 2014 04:18 AM |
Smiley's works, i tried editing it to making it so if it's not a human, it break joints..
local damage = math.random(4,15) function onTouched(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then if hit.Name == "Head" then human.Health = human.Health-damage*2 else human.Health = human.Health-damage end else hit.Parent:BreakJoints() end end script.Parent.Touched:connect(onTouched)
If you want damage to be different for every hit then just tell me. (Right now damage will be the same every time). |
|
|
| Report Abuse |
|
|