I am making a round based game, with different maps. It is a bossfighting game. Each map is a different boss fight. I am trying to get the map to despawn once the round is over using a attribute that is a bool value, but it isnt working.
This is the script where I clone it:
local LobbyWaitTime = 10
local mapwaittime = 10
local GameActive = game.ReplicatedStorage.GameActive
local GameStatus = game.ReplicatedStorage.GameStatus
local CurrentTime
local Players = game:GetService("Players")
local LobbyTeam = game.Teams.Lobby
local PlayingTeam = game.Teams.Playing
local function LobbyTimer()
CurrentTime = LobbyWaitTime
while GameActive.Value == false do
CurrentTime -= 1
GameStatus.Value = "Game Starting in..." .. CurrentTime
if CurrentTime <= 0 then
GameActive.Value = true
end
wait(1)
end
end
local function MapTimer()
CurrentTime = mapwaittime
while GameActive.Value == true do
CurrentTime -= 1
GameStatus.Value = "Game Ending in..." .. CurrentTime
if CurrentTime <= 0 then
wait(2)
GameActive.Value = false
end
local team = game:GetService("Teams").Playing
local players = team:GetPlayers()
if #players == 0 then
GameActive.Value = false
end
wait(1)
end
end
GameActive.Changed:Connect(function(value)
for i, player in pairs(Players:GetChildren()) do
local maps = game.ReplicatedStorage.Maps:GetChildren()
local character = player.Character
local randommap = maps[math.random(1, #maps)]
local mapclone = randommap:Clone()
if value == true then
mapclone.Parent = workspace
player.Team = PlayingTeam
GameStatus.Value = "The ".. randommap.Name.." Has Been Chosen!"
wait(0.5)
elseif value == false then
randommap:SetAttribute("Died", true) -- this prints true, but it doesnt save.
print(randommap:GetAttribute("Died"))
wait(3)
player.Team = LobbyTeam
end
player:LoadCharacter()
end
if GameActive.Value == true then
wait(2)
MapTimer()
elseif GameActive.Value == false then
LobbyTimer()
end
end)
LobbyTimer()
I have a script under the map that is supposed to destroy it:
local lobbyteam = game.Teams.Lobby
while wait(1) do
Players = game:GetService("Players")
for i, player in pairs(Players:GetPlayers()) do
if player.Team == game.Teams.Playing then
script.Parent.Parent:GetAttributeChangedSignal("Died"):Connect(function()
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
script.Parent.Parent:Destroy()
end)
end
end
end