How do I check and return the opposing player’s teamcolor after hit by a rocket?(Anti Team Kill)

My rocket launcher script already works, but I’m trying to make the rocket part not explode on teammates. I have tried soo many things, Please help!

(player) is the person who is holding the tool. And
I have already retrieved the player’s team color.

local team = game:GetService("Teams")
local creatorTeamcolor = player.team

this Script creates an explosion if the criteria are met.

local team = game:GetService("Teams")
local creatorTeamcolor = player.team
	
	
        rocket.Touched:Connect(function(hit)	
		
		for i,v in pairs(players:GetPlayers()) do
			
			if hit == v then
				if hit ~= handle and not tool.Parent:FindFirstChild(hit.name) and hit.v.team ~= creatorTeamcolor then
							
					local explosion = Instance.new("Explosion")
					
					wait(.03)
					explosion.Parent = tool
					explosion.Position = rocket.Position
					explosion.BlastPressure = 2
					explosion.DestroyJointRadiusPercent = 1
					rocket.Anchored = true
					rocket:Destroy()
				end
			end
		end
	end)
end)
1 Like

You can get their player from their character using Players:GetPlayerFromCharacter then compare the hit player’s team against the team of the creator of the rocket.

local teams = game:GetService("Teams")

local myTeam = creator.Team

rocket.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)

		if player then
			if player.Team ~= myTeam then
				-- explode the non-team member
			end
		end
	end
end)
3 Likes

Sorry I had to do something, BUT THANK YOU!!! IT WORKED!!!