I’m currently working on a game. The game include’s this script (map changer script). But sometimes if I play/test the game the script doesn’t work and it shows this error message in the output. If anyone knows how I fix this please let me know!
ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
Status = ReplicatedStorage:WaitForChild('Status')
while true do
wait()
local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
ChosenMap.Parent = workspace
local Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()
Status.Value = 'Choosing Map.'
wait(0.4)
Status.Value = 'Choosing Map..'
wait(0.4)
Status.Value = 'Choosing Map...'
wait(0.4)
Status.Value = 'Choosing Map.'
wait(0.4)
Status.Value = 'Choosing Map..'
wait(0.4)
Status.Value = 'Map chosen.'
local RandomSpawn = Spawns[math.random(0, #Spawns)]
wait(2)
for _, Player in pairs(Players:GetChildren())do
if Player.Character and Player.Character:FindFirstChild('Humanoid') then
Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
end
end
Countdown = 300 -- Game Time
repeat wait(1)
Countdown = Countdown - 1
Status.Value = 'Time Left: '..Countdown
until Countdown <= 0
local replicatedStorage = game:GetService("ReplicatedStorage")
local removeEvent = replicatedStorage:WaitForChild("LoadingScreen")
removeEvent:FireAllClients()
ChosenMap:Destroy()
wait()
Status.Value = 'Round Ended, waiting for new game.'
wait(2)
end