[Help] How to blacklist a team from changing into a different team?

Hey, how would I blacklist a certain team from a spawn pad. For example, I don’t want cops to be able to change into the criminal team when they touch the pad, how would I do this?

Do you even need a script? In the spawn properties, find ChangeTeamOnTouch or something like that and set it to false if you don’t want them to be teamed once the spawn is touched, for a specific team it’s will be a little more easy.

1 Like

Hm, but prisoners need to touch it though, but cops shouldn’t be able to. So, I can’t really do that.

local CopsSpawn = script.Parent -- This is a Part

CopsSpawn.Touched:Connect(function(hit)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if Player then
		if Player.Team ~= "Cops" then return warn("Player is a Criminal") end
		-- Add anything here if they are a cop | or do nothing
	end
end)

-- Not too sure if this would work, In theory it looks like it would.
-- I haven't used Teams before so I'm not sure.

If this doesn’t work I will look into teams and try finding a solution.

1 Like
local blacklisted = script.Parent -- The spawn
local Player = game:GetService("Players")
local Teams = game:GetService("Teams")

blacklisted.Touched:Connect(function(hit)
Player:GetPlayerFromCharacter(hit.Parent) -- Get the player and his character
if Player then
if Player.Team ~= "Cops" then
Player.SetTeam("Criminal")
wait(.2)
Player:LoadCharacter() -- Respawn so the player with example can see the base
else
warn("This player is a cop!")
 end
end)

@TheDCraft You don’t get the Teams Service. And do not set the team. You were almost right.

I am not sure if SetTeam work.

1 Like

Oh right. Yeah I haven’t used teams so I forgot to add the Team Service. Thank you for informing me on that.

1 Like

Also, make sure to use the SetTeam to set the player’s team! You can see more here:

Let’s just wait for the post creator to mark one of us the solution.

1 Like

Player.Team would probably return a error without getting the Team Service.

1 Like

Something like this should work

local CrimSpawn = script.Parent --Or wherever your criminal changer is located

local teams = game:GetService("Teams")

CrimSpawn.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end --If the player doesn't exist from hit.Parent
	if player.Team.Name == "Cops" then print("User touching is a Cop") return end --If the player is in the "Cops" Team

	player.Team = teams["Criminals"]
	
	--player:LoadCharacter() --uncomment this if you would like to respawn the player when they touch the part
end)

This is an example using the Criminal Changer, if whoever is touching is not a player or they’re a cop, the code wont change their team, but if they’re a player and they’re not a cop, it will make them a criminal. Alternatively you can change their team by referencing the team itself

player.Team = teams.Criminals

The first method I used in the example is better for doing that imo, but to each their own

3 Likes

The script worked well, thank you so much!

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like