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

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

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?

1 comment

0

You should use an IntValue instead of a global variable. Just my two cents. Makes it easier to read the value.

2 answers

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

1 comment

0

Thank you for the answer. But, it's not quite what I was looking for.

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

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