String expected, got Instance | Error

Hello, I am getting a error when trying to fire a client.

Script:

local event = game.ReplicatedStorage:FindFirstChild("TeamChange")
local TeamName = 'Civ'
local Players = game:GetService("Players")
script.Parent.MouseButton1Click:Connect(function(plr)
	local susces = game.ReplicatedStorage.TeamChange:InvokeServer(TeamName)
	local player = game.Players.LocalPlayer
	if susces ~= true then 
		event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
	else
		event:FireClient(game.Players[player],"Team Change","You are now on the team you chose!")
	end
end)

The erroring bit

event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
local event = game.ReplicatedStorage:FindFirstChild("TeamChange")
local TeamName = 'Civ'
local Players = game:GetService("Players")
script.Parent.MouseButton1Click:Connect(function(plr)
	local _success, _error = pcall(function()game.ReplicatedStorage.TeamChange:InvokeServer(TeamName)end)
	local player = game.Players.LocalPlayer
	if _error then 
		event:FireClient(game.Players[player],"Team Change Error","There is max players on that team! Please try again later!")
	else
		event:FireClient(game.Players[player],"Team Change","You are now on the team you chose!")
	end
end)

This has the same error (30, 30)

I found this link helpful for this topic. [ Invalid argument #2 (string expected, got Instance)](Invalid argument #2 (string expected, got Instance))

that is when u concat a string with a instance, but i dont see where he does that

Maybe he can use a local script? And not need to fire the client due to it being in a GUI?

game.Players[player.Name] -- return the name of the player.

You’re passing a Player instance instead of a string.

Even better, just use this instead of going through a redundant step:

if susces ~= true then 
		event:FireClient(player,"Team Change Error","There is max players on that team! Please try again later!")
	else
		event:FireClient(player,"Team Change","You are now on the team you chose!")
	end
2 Likes