Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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
0
Thank you, this works! EnderisLTU0 2 — 5y
Ad
Log in to vote
0
Answered by
3ora 54
5 years ago
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)

Log in to vote
-1
Answered by 5 years ago

game.Players.LocalPlayer.TeamColor = lteam.TeamColor

Answer this question