Need help with detecting player teams

Hey Guys

im working on a capture point system and it’s detecting when a player touchs the block and checks their team to change it to the proper color.

Video:
https://gyazo.com/38aade2b5d387f071ac54e79ef8c59e5

The problem is that It detects when I step on it and it changes color to my proper team
But when I change my team it wont change the color,

CODE:

local objective = script.Parent


objective.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		if player.Team.Name == "British" then
			objective.Color = Color3.fromRGB(128,0,0)
		elseif player.Team.Name == "Germany" then
			objective.Color = Color3.fromRGB(0, 92, 138)		
		end
	end
end)

Thank you, any help is loved!

2 Likes

So when you change to Germany, it still shows the colour as red, or does it just not change the colour at all?

Very simple mistake; Just use player.TeamColor instead.

1 Like

Doesnt change anything, after the player switches teams and trys to take the point nothing happens

Does not work, uhh any other tips

2 Likes

Hmm, are you sure you’re doing it correctly?
Here is the page for TeamColor

1 Like

I don’t get your question. Are you trying to change from British to Germany, or Germany to British?

1 Like

Instead of using elseif, try this:

	if player then
		if player.Team.Name == "British" then
			objective.Color = Color3.fromRGB(128,0,0)
        end
		if player.Team.Name == "Germany" then
			objective.Color = Color3.fromRGB(0, 92, 138)		
		end
	end
end)

edit: dumb forum took tab as action instead of space

1 Like

Are you sure you’re changing your team on the server and not just the client? Your code should work the way it is. It’s a common mistake, especially if you’re playtesting in studio.

1 Like