Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make something happen when a player dies?

I want certain things to happen when a player from a certain team dies. For example, I want music to play but my code is not working. Could someone help me/offer me some pointers or let me know if my syntax is wrong? Thanks!

while true do wait()
	local boss = game.Players:GetChildren()
	if boss.TeamColor == 'Bright red' then
		if boss.Character:findFirstChild("Head") ~= nil then --Checks if the physical player exists
			boss.Character:WaitForChild("Humanoid").Died:connect(function()
				print(boss.Name.."has died!")
				game.Workspace.Music:Play()
			end)
		end
	end
end

1 answer

--get when a player joins
game.Players.PlayerAdded:connect(function(player)
    --get when they respawn
    player.CharacterAdded:connect(function(character)
        --get when their character dies
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " was murdered to death.")
        end)
    end)
end)

1 comment

0

I need this only for players of a certain team, I tried something like this but it does not work http://pastebin.com/RZbePsxE

This discussion is preserved as it was. New answers, comments, and votes are closed.