Invalid argument #2 (string expected, got instance)

  1. What do you want to achieve? !
    This script assigns 4 players to their own separate team once it has detected that the round is starting,
  2. What is the issue?
    The script is stopped by this error:
    (Line 21: invalid argument #2 (string expected, got instance)
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I changed line 21 from
    player.Team = game:GetService(“Teams”)[Mint].Name
    to
    game.Players[player].Team = game:GetService(“Teams”).Mint.Name
--max players is 1.
local START = game.Lighting.roundstart
local MaxPlayers = game.Lighting.MaxPlayers



START.Changed:Connect(function()
	local Mint = game.Teams.Mint
	local Violet = game.Teams.Violet
	local Cocoa = game.Teams.Cocoa
	local Royal = game.Teams.Royal

	local plrs = {}

	for i, player in pairs (game.Players:GetPlayers()) do 
		if player then 

			local MintCount = Mint:GetPlayers()
			if #MintCount >= MaxPlayers.Value then
				print ("loading")
			else
				game.Players[player].Team = game:GetService("Teams").Mint.Name
			end
			local VioletCount = Violet:GetPlayers()
			if #VioletCount >= MaxPlayers.Value then
				print ("loading")
			else
				game.Players[player].Team = game:GetService("Teams").Violet.Name
			end        
			local CocoaCount = Violet:GetPlayers()
			if #CocoaCount >= MaxPlayers.Value then
				print ("loading")
			else
				game.Players[player].Team = game:GetService("Teams").Cocoa.Name
			end        
			local RoyalCount = Royal:GetPlayers()
			if #RoyalCount >= MaxPlayers.Value then
				print ("loading")
			else
				game.Players[player].Team = game:GetService("Teams").Royal.Name
			end        



		end
	end

end)

Can you tell me which line is line 21?

1 Like

Try this:

player.Team = game:GetService(“Teams”).Mint

instead of this:

game.Players[player].Team = game:GetService(“Teams”).Mint.Nam
1 Like

game.Players[player].Team is a instance pointing to the team.
Team.Name is a string.
Remove the .name.

Thanks for the suggestion but it still prints the same error.

			game.Players[player].Team = game:GetService("Teams").Mint.Name

You’re calling the players instance

I think if you do player.Name, you will be able to fetch the player.

Does it works if you remove name?

game.Players[player].Team = game:GetService("Teams").Mint
1 Like

TYSM!! The script functioned perfectly

2 Likes