Error "Expected Team got Player for Player:Team."

I was making a team change system for my group’s game, and I got an unexpected error during testing. “Expected Team got Player for Player:Team.”

Critical Components:
RemoteEvent in a folder in ReplicatedStorage
LocalScript in the team change Gui
Script in a folder in ServerScriptService

This is probably an easy fix, please tell me what I did wrong with my code.


LocalScript that send an event on player click

local event = game.ReplicatedStorage.Remotes.ChangeTeam
local team = game.Teams.Immigrants
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer(player, team)
end)

Script that receives the event and changes the player’s team

game.ReplicatedStorage.Remotes.ChangeTeam.OnServerEvent:Connect(function(player, team)
	player.Team = team
end)

Note: The error occurs right after the event is sent and Studio says the error is in the server script.

On the client , no need to provide the player there. It automatically does that.


local event = game.ReplicatedStorage.Remotes.ChangeTeam
local team = game.Teams.Immigrants
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer(team.Name)
end)

game.ReplicatedStorage.Remotes.ChangeTeam.OnServerEvent:Connect(function(player, team)
	player.Team = game:GetService("Teams"):FindFirstChild(team)
end)

1 Like

Thanks a lot! your code fixed it and it works perfectly!

1 Like