Where do I put it? server script service?
1 Like
Yes. Ideally all server scripts should be put there.
Great Script! I was a little worried of having a while loop so I made it so you don’t need to use a while loop:
This should be a script in ServerScriptService
local ReplicatedStorage = game.ReplicatedStorage
local Teams = game.Teams
-- I would name my RemoteEvent and then do local RemoteEvent = ReplicatedStorage.MyNewEventName
local RemoteEvent = ReplicatedStorage:FindFirstChild("RemoteEvent") or Instance.new("RemoteEvent", ReplicatedStorage)
-- Hide Team if Empty
local function DetectTeamNumber()
for i, team in ipairs(Teams:GetTeams()) do
if #team:GetPlayers() == 0 then
RemoteEvent:FireAllClients(team, true)
else
RemoteEvent:FireAllClients(team)
end
end
end
for i, team in ipairs(Teams:GetTeams()) do
team.PlayerAdded:Connect(DetectTeamNumber)
team.PlayerRemoved:Connect(DetectTeamNumber)
end
DetectTeamNumber() -- Keep this if you have Delays in your Script above! If you are Unsure, just keep it! Ima keep mine!
This should be a LocalScript in StarterPlayer → StarterPlayerScripts
local ReplicatedStorage = game.ReplicatedStorage
local Teams = game.Teams
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
-- Set Team Visibility
local function SetTeamVisibility(Team, IsEmpty)
if IsEmpty then
Team.Parent = ReplicatedStorage
else
Team.Parent = Teams
end
end
RemoteEvent.OnClientEvent:Connect(SetTeamVisibility)
1 Like