How do i check if a player is on a team

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

14:05:19.137 Players.ImNotAN00b_0kay.PlayerScripts.LocalScript:4: attempt to index nil with ‘Spys’ - Client - LocalScript:4 i got another error

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

14:06:54.881 Teams is not a valid member of Player “Players.ImNotAN00b_0kay” - Client - LocalScript:4

i even tried adding wait for child

damn i changed the wrong instance of team

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

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