Died event isn't (or doesn't appear to) fired when a player dies?
Game Part Summary:
So in my game, when someone dies all the contents of their backpack are thrown into the workspace as ammo pickups, including the amount of ammo they have.
So here is the script that does that:
01 | local player = game.Players.LocalPlayer |
02 | while player.Character = = nil do wait( 1 ) print "Waiting for character... " end |
03 | local char = player.Character |
04 | print "Character Found!" |
05 | char:WaitForChild( "Humanoid" ) |
06 | char.Humanoid.Died:connect( function () |
08 | char.Humanoid:UnequipTools() |
10 | local backpack = player.Backpack:GetChildren() |
11 | for i = 1 , #backpack do |
12 | if backpack [ i ] ~ = script and backpack [ i ] :IsA( "Tool" ) = = true then |
13 | print ( "Dropping " ..backpack [ i ] .Name.. " tool" ) |
14 | backpack [ i ] .Handle.Position = char.Torso.Position |
15 | backpack [ i ] .Handle.Name = "AmmoPickup" |
16 | backpack [ i ] .AmmoPickup.Script.Disabled = false |
17 | backpack [ i ] .AmmoPickup.Parent = workspace |
20 | print ( "Spitting out " ..script.Parent.Ammo.Value.. " rockets" ) |
21 | for i = 1 , script.Parent.Ammo.Value do |
22 | local clone = game.ReplicatedStorage.Rocket:Clone() |
23 | clone.Position = char.Torso.Position |
24 | clone.Parent = workspace |
Script Location:
This script starts in the StarterPack
, and as expected, is cloned to other player's Backpacks
. This is a LocalScript
Problem:
This script works when players are on a "Spectator" team (i'll change that later; the spectating area fills up with rockets otherwise <_>) but doesn't work when the player is killed so they can be moved to another team. Once they are on that team, the Died
event never fires when they are killed by resetting or being hit by a rocket (the print
functions show me so.) If they move back to Spectators it no longer works. Basically, the event is only ever fired once.
So what am I doing wrong and how can I fix it?