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: 'Drop tools on death' script prematurely firing

Previous Thread :: Next Thread 
Toshi4539 is not online. Toshi4539
Joined: 11 Dec 2008
Total Posts: 210
13 Jun 2012 04:40 PM
Ive written a script to cause all tools that a player is carrying to drop on death, except that it's prematurely firing for no apparent reason, is the problem with my script or with the way roblox handles the Humanoid:Died event?

The dropall() function is called ~5seconds after i spawn(due to the wait()), yet im at full health...

hierarchy:
-Player(Player)
--backpack
---DropToolsOnDeath(Script)
---[other tools]

--DropToolsOnDeath(script)

local pack = script.Parent
local char = pack.Parent.Character
function isdead()
if (char.Humanoid.Health ==0) then
dropall()
end
end
function dropall()

local tools = pack:GetChildren()
print("dropping tools of: " , pack.Parent.Name)
for i, v in ipairs(tools) do
if(v.className == "Tool") then
v.Parent = game.Workspace
v.Handle.Position = char.Torso.Position + Vector3.new(math.random(-5,5),5,math.random(-5,5))--spred the tools around the body
end
end
end
wait(5)
char.Humanoid.Died:connect(dropall())
Report Abuse
nickbricknick464 is not online. nickbricknick464
Joined: 22 Aug 2008
Total Posts: 8302
13 Jun 2012 04:51 PM
why do you need the isdead function?

char.Humanoid.Health ==0 - Try space out that 0 ?
Report Abuse
Swordphin123 is not online. Swordphin123
Joined: 09 Apr 2008
Total Posts: 5234
13 Jun 2012 04:58 PM
"char.Humanoid.Died:connect(dropall())"

You do not need the extra parenthesis.

char.Humanoid.Died:connect(dropall)
Report Abuse
Toshi4539 is not online. Toshi4539
Joined: 11 Dec 2008
Total Posts: 210
13 Jun 2012 05:00 PM
the isdead() was a workaround i was planning to use to fix this problem, idea being that i connect the event to that function to make sure the player really is dead before running dropall(), but then i figured i must be doing something wrong and just left it there because i might use it in the future.

Anyway, i tried both using the isdead() check and adding isdead's code to dropall(), and they both result in now dropall() not doing anything when i die...
Report Abuse
Toshi4539 is not online. Toshi4539
Joined: 11 Dec 2008
Total Posts: 210
13 Jun 2012 05:07 PM
ok, ive take the parenthesis out of the event connect statement, and now my function doesn't run at all...
Report Abuse
nickbricknick464 is not online. nickbricknick464
Joined: 22 Aug 2008
Total Posts: 8302
13 Jun 2012 05:15 PM
Fixed it me thinks



pack = script.Parent -- (Removed local (so it becomes global scope?)
char = pack.Parent.Character -- (Removed local (so it becomes global scope?)
function isdead()
if (char.Humanoid.Health ==0) then
dropall()
end
end
function dropall()

local tools = pack:GetChildren()
print("dropping tools of: " , pack.Parent.Name)
for i, v in ipairs(tools) do
if(v.className == "Tool") then
v.Parent = game.Workspace
v.Handle.Position = char.Torso.Position + Vector3.new(math.random(-5,5),5,math.random(-5,5))--spred the tools around the body
end
end
end
wait(5)
char.Humanoid.Died:connect(dropall) -- remove the () (Not needed)


Report Abuse
Toshi4539 is not online. Toshi4539
Joined: 11 Dec 2008
Total Posts: 210
13 Jun 2012 06:03 PM
ok, now it works!, Thanks!. Btw, ive added to my script the ability to drop stuff that's located in the character model of the player. The script is now available at: http://www.roblox.com/DropToolsONDeath-Script-item?id=83511321
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