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

When a player dies it doesn't change his team?

Hi, i made a script where it changes his team to the lobby on death. But it doesn't work. Can anyone help?

--//Objects\\--
local intermission = 30
local roundtime = 120
local players = game:GetService("Players")
local gun = game.ReplicatedStorage.TrenchGun
local claws = game.ReplicatedStorage.Claws
local wwpackage = game.ReplicatedStorage.Werewolf
local lteam = game.Teams.Lobby
local wteam = game.Teams.Werewolf
local hteam = game.Teams.Hunters
local message = Instance.new("Hint")
message.Parent = workspace
local gamestarted = false
local songs = game.ReplicatedStorage.Songs:GetChildren()
--//Functions\\--
function FindIndex(Table,Val)
	for index,v in pairs(Table) do
		if v == Val then
			return index
		end
	end
end

--//Main\\--
game:GetService('Players').PlayerAdded:Connect(function(player) -- the broken part
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
			player.Team = lteam
		end)
	end)
end)

3 answers

✓ Accepted answer

Put this in a localscript inside startergui.

local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
while wait() do
	if hum.Health == 0 then
		game.Players.LocalPlayer.Team = game.Teams.Lobby
	end
end

1 comment

0

Thank you, this works!

game.Players.PlayerAdded:connect(function(Player) --Just a way for me to get the Player.
Player.CharacterAdded:connect(function(Character) --Just a way for me to get the Player's Character.
repeat wait() until Character:FindFirstChild("Humanoid") ~= nil --Wait's for the Player's humanoid. The basis to a Character's health.
Character.Humanoid.Died:connect(function() --Called when a Player dies.
if Player.TeamColor == game.Teams.Survivors.TeamColor then --Checks to see if the Player was alive, or in other words playing in the 'game round'.
Player.TeamColor = game.Teams.Dead.TeamColor --Changes the player's team, on death.
end
end)
end)
end)

Edit it to your own liking (I'm sure you can do that)

game.Players.LocalPlayer.TeamColor = lteam.TeamColor

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