Flag system does not work

Hello Developers,

I am working on a flag which when a player from different team touches it,the team’s flag transparency becomes 0 and when a player from the other team touches it, the last flag becomes transparency 1 and the the other team’s flag becomes transparency 0.

But it does not work.

Can you help?

Here is my script:

local turkishflag = script.Parent.Turkey
local Players = game:GetService("Players")
local greece = "Greeks"
local turkey = "Ottomans"

script.Parent.Part.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	 if Player then
			print("flag touched by", Player.TeamColor)
			if Player.Team.Name == greece then
				greekflag.Transparency = 0
				print("Greekflag added succesfully")
			end
	 elseif Player.Team.Name == turkey then
			turkishflag.Transparency = 0
			print("turkish flag succesfully added")
	
	
	end
end)

Firstly you should check if the part that touched the other part has a humanoid so you can confirm it is a player. For your main problem you don’t do player.team.name but instead you do player.teamcolor == brickcolor.new(“your team colour”)

1 Like

It works with the one team the other one does not work…

probably because you did the elseif wrong, make sure to look at your if statements to figure out whats wrong

the elseif part should be with the player.teamcolor not with if Player then

       if Player then
			print("flag touched by", Player.TeamColor)
			if Player.Team.Name == greece then
				greekflag.Transparency = 0
				print("Greekflag added succesfully")
		    elseif Player.Team.Name == turkey then
			    turkishflag.Transparency = 0
			    print("turkish flag succesfully added")
	        end
	    end

(indentations may be off as i excruciatingly did it manually)
though i dont see why this wouldn’t work using .Name instead of Player.TeamColor

1 Like

Ι did it my self but you are right so I put you solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.