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 bool value, but it isnt working.
This is the script where I clone it:
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
mapclone.Died.Value = true -- right here is where I activate the bool value but it doesnt work
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)
I have a script under the map that is supposed to destroy it:
local lobbyteam = game.Teams.Lobby
local died = script.Parent.Parent.Died
while wait(1) do
if game.ReplicatedStorage.GameActive.Value == true then
Players = game:GetService("Players")
for i, player in pairs(Players:GetPlayers()) do
if player.Team == game.Teams.Playing then
print(script.Parent.Parent.Parent)
print(died.Value) -- this keeps on printing false, even if i mannualy change the value.
if script.Parent.Parent.Died.Value == true then
print("Value true!")
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100
print("ended!")
script.Parent.Parent:Destroy()
end
end
end
end
end
in the first script that I sent, its a server script, it prints true if I print the value in that script, but it doesnt change it to true if I look at 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
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
mapclone.Died.Value = true
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()
Yes it prints things when I put a print statment, I said earlier, that when I print the value under the first script, its true, but the value doesnt change if I look at it, so the second script wont work.
They are all server scripts the fist one is under serverscriptsevice, the second is under the map, replicated storage, but I clone the map to the workspace.