so i have this script that changes the sky and when the value hits 0 it will delete the sky in lighting and i have 2 teams in my game, the first is black that’s named “Main Menu” and the other is white that’s named “In game” and i want the “in game” teams to be refresh, and not the “Main Menu” team to not get refresh.
local storage = game:GetService("ServerStorage")
local value2 = storage:WaitForChild("Value2")
local sky = script:WaitForChild("Sky")
value2.Changed:Connect(function(newVal)
if newVal == storage.Value.Value then
sky.Parent = game.Lighting
elseif newVal == 0 then
game.Players.LocalPlayer:BreakJoints()
sky:Destroy()
end
end)
local lighting = game:GetService("Lighting")
local teams = game:GetService("Teams")
local storage = game:GetService("ServerStorage")
local players = game:GetService("Players")
local value = storage:WaitForChild("Value")
local value2 = storage:WaitForChild("Value2")
local sky = script:WaitForChild("Sky")
value2.Changed:Connect(function(newVal)
if newVal == value.Value then
sky.Parent = lighting
elseif newVal == 0 then
sky:Destroy()
for _, player in ipairs(players:GetPlayers()) do
if player.Team == teams:FindFirstChild("") then --change to name of ingame team
player:LoadCharacter()
end
end
end
end)
I guess it’s worth saying that there’s a version of GetPlayers for Teams. You could use that instead of checking for a team match since players would already be filtered as you like, since checking team matches reinvents the wheel for this. You can fit this as an alternate loop in what Forummer posted but you do need to replace “YOUR_GAME_TEAM_HERE”. This isn’t a drop-in replacement.
for _, player in ipairs(YOUR_GAME_TEAM_HERE:GetPlayers()) do
player:LoadCharacter()
end
As for preserving tools… you could use StarterGear, collect them yourself and reparent them after using LoadCharacter or just give them completely new copies of the tools they had before. You’d have to know what tools they had first and then set them back.
I was aware of this, I opted against using it in-case additional teams are added in the future (it’s easier to update the conditional statement rather than create multiple arrays for separate teams and iterate over those arrays individually).
Yep, this is fair. It just seemed like OP’s case was geared more towards a single team so I wanted to leave that out there. It may even help out another developer who stumbles across this thread and only uses one team instead. Depends on your use case!
You definitely wouldn’t want to use it if you needed to go through multiple teams though, you’d want your own filter with an array. I’d personally prefer checking for team names or colours rather than instance references though since you’d already end up typing the name anyway.
Oh no that’s fine, you don’t need to do that either. BrickColors are objects, so they have a name property. I used to do this checking for lazy filtering some time back when the Team reference didn’t exist. You probably don’t want to construct a new object for comparison only.
if Player.TeamColor.Name == "Really black" then
You’re more likely to change a team’s colour than its name though… wouldn’t recommend in 2021.