Hello! I am a new scripter and I need help with with this script I’m currently working on. When I play the game, it teleports you to the map. But when the game ends, it doesn’t teleport you back to the lobby.
Here’s the script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local Status = replicatedStorage:WaitForChild("Status")
local InGameBool = replicatedStorage:WaitForChild("InGame")
local MapsFolder = replicatedStorage:WaitForChild("Maps")
local Maps = MapsFolder:GetChildren()
InGameBool.Changed:Connect(function()
if InGameBool.Value == true then
-- Choose Map
local ChosenMap = Maps[math.random(1,#Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace
wait(2)
-- Teleport Players To Map
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = CFrame.new(ClonedMap.Spawn.Position) -- Teleports
end
-- If InGameBool Is False That Means Intermission
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Lobby.SpawnLocation.Position) -- Teleports
end
-- Destroy The Old Map
for i,v in pairs (MapsFolder:GetChildren()) do
if game.Workspace:FindFirstChild(v.Name) then
local obj = game.Workspace[v.Name]
obj:Destroy()
end
end
end
end)
local function changeTimer()
InGameBool.Value = false
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "Intermission "..i.." Seconds Before New Match!"
end
InGameBool.Value = true
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "In Game "..i.." Seconds Left Before Game Ends!"
end
end
while wait() do
changeTimer()
end
Please help me with this, and yes I used a free model (forgot the link sry)
Note: The part that spawns you to the lobby is named "Spawn"
local replicatedStorage = game:GetService("ReplicatedStorage")
local Status = replicatedStorage:WaitForChild("Status")
local InGameBool = replicatedStorage:WaitForChild("InGame")
local MapsFolder = replicatedStorage:WaitForChild("Maps")
local Maps = MapsFolder:GetChildren()
InGameBool.Changed:Connect(function()
if InGameBool.Value == true then
-- Choose Map
local ChosenMap = Maps[math.random(1,#Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace
wait(2)
-- Teleport Players To Map
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = CFrame.new(ClonedMap.Spawn.Position) -- Teleports
end
-- If InGameBool Is False That Means Intermission
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = game.Workspace.Lobby.SpawnLocation.CFrame -- Teleports
end
-- Destroy The Old Map
for i,v in pairs (MapsFolder:GetChildren()) do
if game.Workspace:FindFirstChild(v.Name) then
local obj = game.Workspace[v.Name]
obj:Destroy()
end
end
end
end)
local function changeTimer()
InGameBool.Value = false
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "Intermission "..i.." Seconds Before New Match!"
end
InGameBool.Value = true
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "In Game "..i.." Seconds Left Before Game Ends!"
end
end
while wait() do
changeTimer()
end
local replicatedStorage = game:GetService("ReplicatedStorage")
local Status = replicatedStorage:WaitForChild("Status")
local InGameBool = replicatedStorage:WaitForChild("InGame")
local MapsFolder = replicatedStorage:WaitForChild("Maps")
local Maps = MapsFolder:GetChildren()
InGameBool.Changed:Connect(function()
if InGameBool.Value == true then
-- Choose Map
local ChosenMap = Maps[math.random(1,#Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
task.wait(2)
-- Teleport Players To Map
for _, player in pairs(game.Players:GetPlayers()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = ClonedMap.Spawn.CFrame -- Teleports
end
-- If InGameBool Is False That Means Intermission
else
for _, player in pairs(game.Players:GetPlayers()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = game.Workspace.Lobby.SpawnLocation.CFrame -- Teleports
end
-- Destroy The Old Map
for i,v in pairs (MapsFolder:GetChildren()) do
if game.Workspace:FindFirstChild(v.Name) then
local obj = game.Workspace[v.Name]
obj:Destroy()
end
end
end
end)
local function changeTimer()
InGameBool.Value = false
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "Intermission "..i.." Seconds Before New Match!"
end
InGameBool.Value = true
for i = 10,0,-1 do -- Change The 10 With Your Intermission Timer Dont Mess With The 0 And - 1
wait(1)
Status.Value = "In Game "..i.." Seconds Left Before Game Ends!"
end
end
while task.wait() do
changeTimer()
end
To fix that, you need to go to Game Settings in the top of your screen, publish the game if you haven’t already, and then go to Security on the left bar and Enable the one saying Studio Access to Api Services. This has nothing to do with your main script, though.