I tried to make a script by making a team with a custom name by typing the name and pressing a button on a GUI with FE, as I am learning about RemoteEvents, but when I tried assigning a team to the player I got this error:
13:32:43.078 - ServerScriptService.MakeTeam:7: bad argument #2 to '?' (string expected, got Object)
Here are the scripts
Local Script on the Button:
local button = script.Parent local box = script.Parent.Parent.TeamName button.MouseButton1Click:Connect(function() game.ReplicatedStorage.Events.MakeTeam:FireServer(box.Text) end)
Script on ServerScriptService
game.ReplicatedStorage.Events.MakeTeam.OnServerEvent:Connect(function(player, teamName) local team = Instance.new("Team") team.Parent = game:GetService("Teams") team.Name = teamName team.TeamColor = BrickColor.Random() game:GetService("Players")[player].Neutral = false game:GetService("Players")[player].Team = team.Name end)
On lines 7 and 8, your passing a player into the the brackets. They rely on a string instead, the string being the name of the child. Here's the fixed server script:
game.ReplicatedStorage.Events.MakeTeam.OnServerEvent:Connect(function(player, teamName) local team = Instance.new("Team") team.Name = teamName team.TeamColor = BrickColor.Random() team.Parent = game:GetService("Teams") -- Parenting is now done last game:GetService("Players")[player.Name].Neutral = false -- Now uses string game:GetService("Players")[player.Name].Team = team.Name -- Now uses string end)
Also, just going to add, you should parent the team to the teams service last. There's been some research done on the devforum showing parenting a new instance is best when done at the end. I have this small fix included above.
So what that error means is that coded wanted a string like example "ThisIsString" but instead it got object which is like a table I think
So what I suggest you do is before the :FireServer(box.Text)
add print(box.Text)
to see if it is a string
And beforelocal team = Instance.new("Team")
code add
print("What is player name"..player.Name)
print("What is team name"..teamName)
That is to see what those 2 parameters is and if teamName is a string.