Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I fix this script about making a custom team with Filtering Enabled?

Asked by 6 years ago

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)
0
What is box? Is it a TextLabel? PlaasBoer 275 — 6y
0
Box is most likely a TextBox. Dog2puppy 168 — 6y

2 answers

Log in to vote
0
Answered by
Dog2puppy 168
6 years ago

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.

0
Ah, I see. Thanks for helping :) SirDerpyHerp 262 — 6y
Ad
Log in to vote
0
Answered by
PlaasBoer 275 Moderation Voter
6 years ago
Edited 6 years ago

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.

Answer this question