How do i check if a player is on a team

I want to make it so it prints something when the player is on red team

It dosent print anything doe Which is the problem

i tried changing it into a string anything and didnt work and i didnt look in the devhub

i dont know what else to type here but i really need it for my game

local player = game.Players.PlayerAdded:Connect(function()
	local Team = game:GetService("Teams")
	wait(1)
	if player.Team == "Spys" then
		print("Player is on spy team")
	end
end)
2 Likes

player.Team is an object value, not a string value. If you want to verify the team name, do “player.Team.Name == “the team’s name””. Otherwise it will be “player.Team == game.Teams.TeamObject”.

Replace this

if player.Team == "Spys" then

with

if player.Team == game.Teams.Spys then
1 Like

It didnt work doe i already tried that doe

oh the code is flawed I think

 game.Players.PlayerAdded:Connect(function(plr)
	local Team = game:GetService("Teams")
	wait(1)
	if plr.Team == Teams.Spys then
		print("Player is on spy team")
	end
end)

that version of the code also didnt work

What sort of script is it? Server or local

i tried that dosent work i think

its a local script Does it have to be server one?

For playeradded to work, it has to be a server script

if you want it to be a local script, just remove the PlayerAdded thing and add

local plr = game.Players.LocalPlayer

at the start of the script

i got this error PlayerScripts.LocalScript:7: Expected , got ‘end’

please paste your current code

local plr = game.Players.LocalPlayer
local Team = game:GetService(“Teams”)
wait(1)
if plr.Team == Teams.Spys then
print(“Player is on spy team”)
end
end)

local plr = game.Players.LocalPlayer
local Team = game:GetService(“Teams”)
wait(1)
if plr.Team == Teams.Spys then
    print(“Player is on spy team”)
end

@TommieLesley this should work now ^

wait how do i make it a lua text

local plr = game.Players.LocalPlayer
	local Team = game:GetService("Teams")
	wait(1)
	if plr.Team == Teams.Spys then
		print("Player is on spy team")
	end
end)

I fixed the code in the message above your one.


To get syntax highlighting (“lua text”, as you put it)
```
before and after the code, on lines before and after the code, not the same line
It’s the character near the top left of your keyboard

1 Like

ok but how do i fix that error
13:57:45.582 Players.ImNotAN00b_0kay.PlayerScripts.LocalScript:7: Expected , got ‘end’ - Studio - LocalScript:7

image
You don’t need the last end.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Teams = game:GetService("Teams")

task.wait(1)
-- What do you need the wait for?
if LocalPlayer.Team == Teams.Spys then
	print("Player is on spy team")
end
1 Like

I already posted and sent you to the correct one multiple times, but here it is again:

local plr = game.Players.LocalPlayer
local Team = game:GetService(“Teams”)
wait(1)
if plr.Teams == Teams.Spys then
    print(“Player is on spy team”)
end