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 come this damage script doesn't work?

Previous Thread :: Next Thread 
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
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
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 06:22 PM
Bump...
Report Abuse
sekretaryuk is not online. sekretaryuk
Joined: 26 Oct 2009
Total Posts: 840
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 is not online. 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
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
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
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 07:20 PM
Bump..
Report Abuse
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 07:30 PM
another bump...
Report Abuse
lolb3 is not online. 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
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
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 is not online. Avner
Joined: 30 Nov 2007
Total Posts: 3390
01 Jan 2014 07:51 PM
too many ends
Report Abuse
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 08:18 PM
Bump....
Report Abuse
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 09:02 PM
Yet another bump...
Report Abuse
quickfrozen is not online. quickfrozen
Joined: 28 Dec 2009
Total Posts: 382
01 Jan 2014 09:17 PM
Uhhg.. how is "hit" a nil value???
Report Abuse
smiley599 is not online. 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
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