What's wrong with my team changer?

Alright so the Nurse team is like acting up, anyone can join even if they don’t own the game pass and I’ve been attempting to fix it but failed.

game.ReplicatedStorage.Events.TeamEvent.OnServerEvent:Connect(function(player, text)
	print("RECIEVED EVENT")
if game.Players[player.Name].Team.Name ~= "Timeout" then
	if text == "Nurse" then
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 7220221) then
		player.TeamColor = game.Teams:FindFirstChild(text).TeamColor
		player:LoadCharacter()		
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(0, 255, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Successfully joined Nurse team."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs			
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 7220221)
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(255, 0, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Failed to join Nurse team, you don't own this pass."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs			
		end
	end
	
	if text == "Manager" then
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 9347391) then
		if game.ReplicatedStorage.ManagerJoinStatus.Value == true then
		player.TeamColor = game.Teams:FindFirstChild(text).TeamColor
		player:LoadCharacter()		
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(0, 255, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Successfully joined Manager team."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs			
		else
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(255, 0, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Failed to join Manager team, Max Players that can join Manager is 1! Please wait for the player to leave team or join another server."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs	
		end	
		else			
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 9347391)
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(255, 0, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Failed to join Manager team, you don't own this pass."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs
	end
else
	if text == "Lifeguard" then
		if game.ReplicatedStorage.LifeguardJoinStatus.Value == true then
		player.TeamColor = game.Teams:FindFirstChild(text).TeamColor
		player:LoadCharacter()		
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(0, 255, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Successfully joined Lifeguard team."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs		
	else
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(255, 0, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Failed to join Lifeguard team, This team is full!"
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs	
	end
	else		
		player.TeamColor = game.Teams:FindFirstChild(text).TeamColor
		player:LoadCharacter()
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(0, 255, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Successfully joined "..text.." team."
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs	
		end 
		end
	else
		local OutputText = game.ReplicatedStorage.OutputText:Clone()	
		OutputText.TextColor3 = Color3.fromRGB(255, 0, 0)
		OutputText.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
		OutputText.Text = "Ha nice try! Wait till your timeout is over before team changing!"
		OutputText.LocalScript.Disabled = false
		OutputText.Parent = game.Players[player.Name].PlayerGui.Menus.Outputs
	end
end)

It’s super hard for me to keep track of the scopes in your script because of devform indentation. Add a print statement directly after the UserOwnsGamepassAsync() for Nurse, and see if it prints on a user who doesn’t own the game pass. I want to make sure it’s this part of your script that is teaming the player to “Nurse”

1 Like