Team is not a valid member of Players "Players"

I’m having issues with player and its teams.
Im trying to make it when a player click on something the script check if its in a specific team but it keeps giving me the error; Team is not a valid member of Players “Players” .

Heres my code:

local C4Module = require(script.Parent:WaitForChild("C4Module"))
local Player = game:GetService("Players")
local Team = game:GetService("Teams")["Blue"]

script.Parent.ClickDetector.MouseClick:Connect(function(part)
	if debounce == true then
		debounce = false
		if Player.Team == Team then
			C4Module.c4_setup()
			C4Module.explode()
			wait(240)
			C4Module.restore()
			wait(180)
			script.Parent.Cooldownlift2:Play()
			script.Parent.SelectionBox.Color3 = Color3.fromRGB(255,0,0)		
		end
	end
end)

It’s because the variable player is the service called “Players”, not the actual players.

1 Like

I changed it from

local Player = game:GetService("Players")

to

local Player = game.Players.LocalPlayer

And the error have been fixed but a new one appeared:
attempt to index nil with ‘Team’

You’re not comparing the player to the team - you’re comparing the Players service with a property Team (which it doesn’t have) to the Team variable. To fix this, you can add .LocalPlayer to your Player variable. (Assuming this is a LocalScript)

A click detector returns the player who clicked it - perhaps this is what you were tryna do? (Assuming this is a Script)

local C4Module = require(script.Parent:WaitForChild("C4Module"))
local Team = game:GetService("Teams")["Blue"]
local debounce = true

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	if debounce == true then
		debounce = false
		if Player.Team == Team then
			C4Module.c4_setup()
			C4Module.explode()
			wait(240)
			C4Module.restore()
			wait(180)
			script.Parent.Cooldownlift2:Play()
			script.Parent.SelectionBox.Color3 = Color3.fromRGB(255,0,0)		
		end
	end
end)

I hope this helped. :slight_smile:

EDIT

Glad I could help. :smile:

2 Likes

thank you I was so tired trying hours to figure it out I’m so silly thank you so much.

1 Like