I need to have my script run in game but it does not work.
There is no errors when it runs.
--wait(5)
local maps = game.ServerStorage.Maps:GetChildren()
local currentmap = workspace:WaitForChild("CurrentMap")
local chosenmap = game:GetService("ReplicatedStorage"):WaitForChild("ChosenMap")--script:WaitForChild("ChosenMap")
local spawner = workspace.Lobby:WaitForChild("Spawn")
local roundtime = 90 --180
local inter = 15 --30
local tweenService = game:GetService("TweenService")
spawn(function()
_G.lastmap = nil
function PickMap()
local choices = {}
for i = 1, #maps do
if maps[i]:IsA("Model") then
table.insert(choices, maps[i])
end
end
repeat
_G.picked = math.random(1,#maps)
wait()
until choices[_G.picked].Name ~= _G.lastmap
_G.lastmap = choices[_G.picked].Name
chosenmap.Value = choices[_G.picked].Name
end
spawn(function()
function LoadMap()
local map = game.ServerStorage.Maps:FindFirstChild(chosenmap.Value):Clone()
map.Parent = currentmap
map:WaitForChild("Spawn").SpawnLocation.Enabled = true
spawner.SpawnLocation.Enabled = false
if map.Name == "Chair" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.Chair.ShopChair.CFrame)
else
if map.Name == "Arena" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.Arena.ShopArena.CFrame)
end
if map.Name == "HappyHome" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.HappyHome.ShopHappyHome.CFrame)
end
if map.Name == "SwordHeights" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.SwordHeights.ShopSwordHeights.CFrame)
end
if map.Name == "Crossroads" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.Crossroads.ShopCrossroads.CFrame)
end
if map.Name == "Haunted" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.Haunted.ShopHaunted.CFrame)
end
if map.Name == "GlassHouses" then
workspace:WaitForChild("Shop"):SetPrimaryPartCFrame(workspace.CurrentMap.GlassHouses.ShopGlassHouses.CFrame)
end
end
end end)
function DestroyMap()
for i,v in pairs(currentmap:GetChildren()) do
if v:IsA("Model") then
v:WaitForChild("Spawn").SpawnLocation.Enabled = false
spawner.SpawnLocation.Enabled = true
v:Destroy()
end
end
end
function teleportPlayers()
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value):WaitForChild("Spawn").CFrame
end
end
function teleportBack()
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
v.Character.HumanoidRootPart.CFrame = spawner.CFrame
end
end end)
spawn(function()
while wait(0.1) do
if game:GetService("ReplicatedStorage").Round.Value == false then
for i,v in pairs(game.Players:GetChildren()) do
repeat wait() until v.Character.Humanoid.Health == 100
end
local players = game:GetService("Players")
--ACTIVATE FOR ACTUAL GAME --repeat wait() until #game.Players:GetPlayers() >= 2
PickMap()
for i,v in pairs(game.Players:GetChildren()) do
if v.Character then
repeat wait() until v.Character.Humanoid.Health > 0
LoadMap()
end
end
--end
game:GetService("ReplicatedStorage").RoundTimer.Value = inter
wait(inter)
teleportPlayers()
game:GetService("ReplicatedStorage").Round.Value = true
game:GetService("ReplicatedStorage").RoundTimer.Value = roundtime
end end end)
spawn(function()
while wait(0.1) do
if game:GetService("ReplicatedStorage").Round.Value == true and game:GetService("ReplicatedStorage").RoundTimer.Value == 0 then
for i,v in pairs(game.Players:GetChildren()) do
if v.Character.Humanoid.Health == 100 then
teleportBack()
else
repeat wait() until v.Character.Humanoid.Health == 100
teleportBack()
end
---end
--teleportBack()
DestroyMap()
game:GetService("ReplicatedStorage").Round.Value = false
for i,v in pairs(game.Players:GetChildren()) do
v.leaderstats.Heads.Value = 0
v.leaderstats.Deaths.Value = 0
if not v.Character:FindFirstChild("Crown") then
else
v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1
end
end
for i,v in pairs(game.Workspace:GetDescendants()) do
if v.Name == "Crown" then
v:Destroy()
end
if v.Name == "Crown2" then
v:Destroy()
end
end
end
end end end)