How can i make it so that a person on the criminal team has the tag ‘enemy’
and a person on the police team has the tag ‘friend’
i tried it and it works for when a player spawns,but when they switch teams,the tag does not get replaced/removed
please help,ty
Do you ever change/remove the tag? You gave no script.
local CollectionService = game:GetService("CollectionService")
-- Function to add a tag to a player
local function AddTag(player, tag)
if not CollectionService:HasTag(player, tag) then
CollectionService:AddTag(player, tag)
end
end
-- Function to remove a tag from a player
local function RemoveTag(player, tag)
if CollectionService:HasTag(player, tag) then
CollectionService:RemoveTag(player, tag)
end
end
-- Function to handle player team changes
local function OnPlayerTeamChanged(player)
local team = player.Team
-- Remove the previous tag based on the old team
if CollectionService:HasTag(player, "SoldierFriend") or CollectionService:HasTag(player, "SoldierEnemy") then
RemoveTag(player, "SoldierFriend")
RemoveTag(player, "SoldierEnemy")
end
-- Add the new tag based on the new team
if team and team.Name == "Police" then
AddTag(player, "SoldierFriend")
elseif team and team.Name == "Prisoner" then
AddTag(player, "SoldierEnemy")
end
end
-- Get the player
local player = script.Parent
-- Add tags based on the initial team
local initialTeam = player.Team
if initialTeam and initialTeam.Name == "Police" then
AddTag(player, "SoldierFriend")
elseif initialTeam and initialTeam.Name == "Prisoner" then
AddTag(player, "SoldierEnemy")
end
-- Attach OnPlayerTeamChanged function to player teamChanged event
player.TeamChanged:Connect(function()
OnPlayerTeamChanged(player)
end)