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

How do I add a point to one team when a member of the other dies?

Asked by 6 years ago

This is the code:

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()          
            print(player.Name,player.Team,player.TeamColor)

            if player.Team == "Red" then 
                _G.claimed = _G.claimed + 1
            end

When I reset the game outputs my player name and my team/team brick colour as it's supposed to (Line 4).

The team name it outputs is "Red".

The if statement says if the player is on red add a point. (Of course this only happens when the player dies)

My problem is that it for some reason doesn't add the point. If I remove the if statement it works but it'll give the point even if blue dies (I only want to add the point if red dies).

How can I make this work?

0
You should use an IntValue instead of a global variable. Just my two cents. Makes it easier to read the value. DatOneRandomDude 69 — 6y

2 answers

Log in to vote
0
Answered by
FPSVision -14
6 years ago
Edited 6 years ago

This should work I think.

game.Players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local currency1 = Instance.new("IntValue",folder) currency1.Name = "Points" player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() local tag = character.Humanoid:FindFirstChild("creator") if tag ~= nil then if
0
Thank you for the answer. But, it's not quite what I was looking for. LoganRMX 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I figured it out.

Instead of checking if they are in red team by doing:

if player.Team == "Red" then

You shouldn't use a string. So, it worked by doing this:

local RedTeam = game.Teams.Red
if player.Team == RedTeam then

Answer this question