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 |
|
|
|
| 13 Jun 2012 04:51 PM |
why do you need the isdead function?
char.Humanoid.Health ==0 - Try space out that 0 ? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|