Sorry for the weird phrasing, this is a weird issue in general.
I have a map system that spawns in flags that the teams collect, and in the first round it works fine, then when it gets destroyed after the map is reset then respawned, they can’t be collected anymore, which leads me to believe they aren’t getting recognized. They have the same name and everything.
Code Snippet:
local RedFlag = FlagService.new(RedTeam, workspace.Map:WaitForChild("RedFlagPad"))
local BlueFlag = FlagService.new(BlueTeam, workspace.Map:WaitForChild("BlueFlagPad"))
local GreenFlag = FlagService.new(GreenTeam, workspace.Map:WaitForChild("GreenFlagPad"))
local YellowFlag = FlagService.new(YellowTeam, workspace.Map:WaitForChild("YellowFlagPad"))
This is the part referencing the flags, it’s inside of a function that gets referenced in a while loop when the map is cloned.
What code you need to see? I can show you the while loop.
while true do
-- Intermission
local intermissionTime = 10
for i = intermissionTime, 0, -1 do
Status.Value = "Intermission: " .. i
assignPlayersToLobbyTeam()
wait(.25)
end
destroyMap()
local ChosenMap = Maps[math.random(#Maps)]
local ClonedMap = ChosenMap:Clone()
for _, mapObject in ipairs(ClonedMap:GetChildren()) do
local newMapObject = mapObject:Clone()
newMapObject.Parent = mapFolder
end
print("Map: " .. ClonedMap.Name)
Status.Value = "Map: " .. ClonedMap.Name
wait(2)
local players = Players:GetPlayers()
for _, player in ipairs(players) do
local teamIndex = math.random(1, #teams - 1)
player.Team = teams[teamIndex]
end
wait(.1)
resetPlayers()
-- Set the skybox of the map in the Lighting
local mapSkybox = ClonedMap:FindFirstChild("Sky")
if mapSkybox then
Lighting.Sky.SkyboxBk = mapSkybox.SkyboxBk
Lighting.Sky.SkyboxDn = mapSkybox.SkyboxDn
Lighting.Sky.SkyboxFt = mapSkybox.SkyboxFt
Lighting.Sky.SkyboxLf = mapSkybox.SkyboxLf
Lighting.Sky.SkyboxRt = mapSkybox.SkyboxRt
Lighting.Sky.SkyboxUp = mapSkybox.SkyboxUp
end
local timeOfDayString = ClonedMap:FindFirstChild("TimeOfDay")
local timeOfDay = timeOfDayString and timeOfDayString.Value or "12:00:00"
Lighting.TimeOfDay = timeOfDay
local roundDurationString = ClonedMap:FindFirstChild("RoundDuration")
local roundDuration = roundDurationString and tonumber(roundDurationString.Value) or 60
-- Round
for i = roundDuration, 0, -1 do
Status.Value = "Game: " .. i
wait(1)
end
for _, player in ipairs(players) do
teleportPlayerToLobby(player)
end
-- Clean up
destroyMap()
end