how can you create a script that ensures that when there is no player in a specific team, that specific team disappears and when a new player joins the specific team, that specific team returns?
I would do something like:
if team:GetChildren() == nil then
team:Destroy()
To destroy it, for making it reappear I would make variables that have all the information about the team and then do this:
Players.PlayerAdded:Connect(function(player)
player.Team = Instance.new(“Team”)
--here you would put the variables with the info
end
i tried it and it doesn’t work
Something like this could work for the removing part.
local Team = -- Path to your team
Team.PlayerRemoved:Connect(function(Player)
if #Team:GetPlayers() == 0 then
Team:Destroy()
end
end)
Instead of destorying it, we could parent it to something else in a folder that is named “CurrentUnused” in Server Storage or replicated storage. (You can destory it i you want but you’re going to have to instance the team again.)
When A player presses or touches something that makes them join the team. Parent it back to the Teams folder and add them right back in
local Team = game:GetService("Teams")
if Team:FindFirstChild("SpecificTeam") then
Player.Team = Team.SpecificTeam
else
unusedfolder.SpecficTeam.Parent = game.Teams
Player.Team = Team:WaitForChild("SpecficTeam")
end
And to remove the team when there is no players in the team. (@4667hp made most of this, thank him)
local Team = -- Path to your team
Team.PlayerRemoved:Connect(function(Player)
if #Team:GetPlayers() == 0 then
Team.Parent = game:GetService("ReplicatedStorage"):WaitForChild("UnusedFolder")
end
end)
Most of this need you to fill it
but the team doesn’t want to disappears after i left the team
here script:
local Team = game:GetService(“Teams”)
local player = script.Parent.Parent
local unusedfolder = game.ReplicatedStorage.UnusedFolder
if Team:FindFirstChild(“SpecificTeam”) then
player.Team = Team.SpecificTeam
else
unusedfolder.SpecficTeam.Parent = game.Teams
player.Team = Team:WaitForChild(“SpecficTeam”)
end
local Team = game.ReplicatedStorage.UnusedFolder.SpecficTeam – Path to your team
Team.PlayerRemoved:Connect(function(Player)
if #Team:GetPlayers() == 0 then
Team.Parent = game:GetService("ReplicatedStorage"):WaitForChild("UnusedFolder")
end
end)
what is wrong?
I know it doesn’t work, it’s only meant to be a base, also it’s written on the DevForum, so it’s obvious that it doesn’t work
I do not think there is a way to make a team disappear without using a custom leaderboard.
I think he meant destroying it? Not sure thi
sorry for not clarifying, I meant to quote this
so that you don’t see it when no one is in the team
Okay, so basically the script I sent you is a very basic version of that, but it’s not the full script, as I said, it needs to be adapted
I can’t write the whole scritto for you, it’s aagainst the rules
sadly I’m not good at scripting but thanks for trying to help me
I tested it without using a script and it works. You just need to assign the player to the team after wards just incase.