Your way automatically puts them on the team, meaning it’s not a check, you’ve just defeated the purpose of what @TheGameGod_YT is trying to make
I don’t know… maybe scroll to the top?
Sorry if I’m coming across rude, that’s not my intent and I know your only trying to help. We’re all programmers at the end of the day.
I’d recommend going with the script I made since your while loop is infinitely yielding which may cause crashes.
local players = game:GetService('Players')
local player = players.LocalPlayer
local teams = game:GetService('Teams')
local checkTeam = function()
if player.Team == teams:FindFirstChild('Police') then
print('The player is on the police team!')
end
end
player:GetPropertyChangedSignal('Team'):Connect(checkTeam)
checkTeam()
Try to debug it using print.
local Player = game.Players.LocalPlayer
repeat wait() until Player -- Waits for player to load
local Team = game.Teams
print(Player.Team) -- Prints the player team. If it prints nil or something that it means player isnt in the team or you can just check the player team in the playerlist.
you need to check for when the team changes.
game.Players.PlayerAdded:Connect(function(plr)
plr:GetPropertyChangedSignal("Team"):Connect(function()
if plr.Team == game.Teams.Police then
print("Police")
end
end)
end)
nevermind, someone already said this.
In a local script this will only ever work for the local player, consider using the “PlayerAdded”/“PlayerRemoved” events of team instances instead.
local Teams = game:GetService("Teams")
for _, Team in ipairs(Teams:GetTeams()) do
Team.PlayerAdded:Connect(function(TeamPlayer)
print(TeamPlayer.Name.." joined "..Team.Name..".")
end)
Team.PlayerRemoved:Connect(function(TeamPlayer)
print(TeamPlayer.Name.." left "..Team.Name)
end)
end
This script is both local and will work for all players and all teams.
I’m not sure why everyone in this thread neglected those events as they are incredibly useful (and operate in both server scripts & local scripts).