Team script not working

So I have made a local script that detects if you are in a team and if you are in that specific team it will allow you to see all the proximity promts in workspace. I don’t get an error so I wonder whats the problem.

local team = game.Teams.MI5
local team2 = game.Teams["Development Team"]
local player = game:GetService("Players")
local teams = game:GetService("Teams")

player.PlayerAdded:Connect(function(player)
	if player.Team == teams.MI5 then
		for i,v in pairs(game.Workspace:GetDescendants()) do
			if v:IsA("ProximityPrompt") then
				v.Enabled = true
		end
		end
	end
	if player.Team == teams["Development Team"] then
		for i,v in pairs(game.Workspace:GetDescendants()) do
			if v:IsA("ProximityPrompt") then
				v.Enabled = true
			end
			end
	end
end)
1 Like

Why not do this in a Server Script, also you defined the teams at the top so you could just do

if player.Team = team then -- First If statement

if player.Team == team2 then -- 3rd if statement
1 Like

But I want the proximity prompt to only activate for them if they are in that team.

1 Like

The code seems to me like no matter what team they are on they are going to get the same prompt. If you try and use print statements to see if the script it working then you could locate where the problem is.

1 Like

I did that and it didn’t even print from the start.

1 Like

Could move this to a Server Script and I can guide you from there.

2 Likes

Ok thanks I will do just that.

1 Like

Ok I did just that and added print statements. But its printed like over 100 times even thought its player added.

1 Like

Did you add the print into the for loop, that’s why its printing a lot.

1 Like

There is no for loop. Here

local team = game.Teams.MI5
local team2 = game.Teams["Development Team"]
local player = game:GetService("Players")
local teams = game:GetService("Teams")

player.PlayerAdded:Connect(function(player)
	print(32)
	if player.Team == teams.MI5 then
		for i,v in pairs(game.Workspace:GetDescendants()) do
			if v:IsA("ProximityPrompt") then
				v.Enabled = true
			end
		end
	end
	if player.Team == teams["Development Team"] then
		for i,v in pairs(game.Workspace:GetDescendants()) do
			print("heah")
			if v:IsA("ProximityPrompt") then
				v.Enabled = true
				print("32r")
			end
		end
	end
end)
1 Like

for i,v in pairs(game.Workspace:GetDescendants()) do is a for loop.

1 Like

Yea you are right, but how do i make it so if they are in that team it shows the proximity promt localy.

1 Like

I could do remote events, but lets see what you have to say.

1 Like

I would recommend making two folders in workspace, called [Team1Name] and [Team2Name]

The if the player was in Team1, loop through the Team1Name Folder and enable it and the same for the other team.

1 Like

But it’s a server sided script.

1 Like

Yeah, I’m not too familiar with proximity prompts but they should only interact with the client regardless of where the script is. I’m not sure but I think this may be the case.

1 Like

Try doing this (change team colors to the respective team colors for Development Team and MI5)


local player = game:GetService("Players")

player.PlayerAdded:Connect(function(player)
	if player.TeamColor == BrickColor.new("Bright blue") or player.TeamColor == BrickColor.new("Bright red")then
		for i,v in pairs(game.Workspace:GetDescendants()) do
			if v:IsA("ProximityPrompt") then
				v.Enabled = true
			end
		end
	end
end)

I wouldn’t name the variable representing “Players” player. This will 100% work if you place it in a server script in server script service, I just finished testing it.

1 Like

I see this in a lot of code, (player.team) It doesn’t always work so Try player.Team.Name

2 Likes