Hello everyone, I just have some trouble determining how to make a function so that it detects the player’s team and prints it on the console. I might be doing something wrong, so I am open to any suggestions. I am aware that I am not allowed to ask for people to write code for me, so if anyone would point me in the right direction, that would be great.
My code:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local function detectTeam(player)
if player.Team == Teams.TeamA then
print("You are TeamA")
end
end
detectTeam()
Output:
09:16:39.566 - Players.bootsareme.PlayerGui.MenuControl:34: attempt to index nil with 'Team'
Note: I have two teams named TeamA and TeamB already. My script is in StarterGui because I am trying to prompt GUI’s to the respective teams.
local Players = game:GetService("Players")
local TeamService = game:GetService("Teams")
local function detectTeam(player)
if player.Team == TeamService.TeamA then
print("You are TeamA")
end
end
detectTeam()
local Teams = game:GetService("Teams")
local player = game.Players.LocalPlayer
local function detectTeam()
if player.Team == Teams.TeamA then
print("You are TeamA")
end
end
detectTeam()