Need Help with Script that Removes a Team

I have a faction menu that allows you to create a team and automatically puts the local player in it, but I wanted to create a remove-team event that moves the team to a folder. I sent a parameter from the client to the server to find the team using FindFirstChild(), but I can’t find out why it isn’t finding the team.

Here’s my code:

Server

RemoveTeam.OnServerEvent:Connect(function(player, team)
	print(team)
	local Teams = game.Teams
	local find = Teams:FindFirstChild(team)
	find.Parent = Teams.NotInUse
end)

Client

script.Parent.MouseButton1Click:Connect(function()
	local team = game.Players.LocalPlayer.Team
	print(team)
	game.ReplicatedStorage.Factions.RemoveTeam:FireServer(team)
	wait()
	script.Parent.Parent.Parent.Menu.Visible = false
end)

Output

Any help is appreciated, thank you.

because since the variable find is a FindFirstChild, and the team doesn’t exist, it returns nil. Nil does not have a parent property. Try this:
Server

RemoveTeam.OnServerEvent:Connect(function(player, team)
	print(team)
	local Teams = game:GetService("Teams")
        local find = Teams:FindFirstChild(team)
	if find then find.Parent = Teams.NotInUse; end
end)

This checks if it is nil, and if so, doesn’t do anything.

1 Like

This didn’t work too well since it seems like it’s returning nil.

Because in one of your other scripts, the team isn’t being made or something

It is creating a team.

Is the team being made from the client? That may be why the server cant find it

No, that’s the reason why I created a RemoveEvent.

If the script that made the team is a local script, then the server wont be able to find it. It will only appear for one player.

I created the team through the server though, using a RemoveEvent.

Try changing it like this

local find = Teams:FindFirstChild(team.Name)

I think it only accepts names and not instances, you can also pass the name instead of the instance through the remote event

1 Like

Yeah you were right. Thanks man.