So I am making a game and I have a maps that are randomly picked and after the round I am trying to destroy them with :Destroy() but it wont work. Can someone help me with this? Everything else works except this.
Code
Maps = {"Campout", "Pyramid", "Temple"} intermission = 5 -- time until flood comes gamewait = 5 -- how long the flood stays numofplayers = 1 -- How many players are required to play timebeforeround = 5 --Time before flood wait() function m(update) c = game.Players:GetChildren() for i=1, #c do c[i].PlayerGui.InformationGui.Frame.TextLabel.Text = "" .. update end end while true do wait(1) if game.Players.NumPlayers >= numofplayers then for i=1, intermission do wait() m("The next flood will strike in: " .. intermission -i) wait(1) end pl = game.Players:GetChildren() for i=1, #pl do pl[i].Playing.Value = true end rndum = math.random(#Maps) cmap = Maps[rndum] -- This picks a random map game.Lighting[cmap]:Clone().Parent = game.Workspace m("Picking a map .") wait(1) m("Picking a map ..") wait(1) m("Picking a map ...") wait(1) m("The chosen map is " .. cmap) wait(2) plpl = game.Players:GetChildren() for i=1, #plpl do if plpl[i].Playing.Value == true then cspawn = game.Workspace.Part target = CFrame.new(cspawn.Position) for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0) end end --plpl[i].Character.Humanoid.WalkSpeed = 0 end end for i=1, timebeforeround do m("The Flood is coming in " .. timebeforeround - i) wait(1) end m("It's here!") local platform = workspace.Place.Platform platform.Material = "Foil" platform.Size = Vector3.new(500,100,300) local storage = game:GetService("Lighting") local part = storage["Kill"]:clone() part.Parent = platform part.Disabled = false wait(1) getlpa = game.Players:GetChildren() for i=1, #getlpa do if getlpa[i].Playing.Value == true then getlpa[i].Character.Humanoid.WalkSpeed = 16 lp = getlpa[i]:GetChildren() for b=1, #lp do --if lp[b].ClassName == "Tool" then --lp[b]:Clone().Parent = getlpa[i].Backpack end end end end for i=1, gamewait do m("The Flood ends in: " .. gamewait - i) wait(1) end getlpas = game.Players:GetChildren() m("The Flood is gone.") local platform = workspace.Place.Platform platform.Material = "Cobblestone" platform.Size = Vector3.new(500,2,300) platform.Kill:Destroy() cmap = Maps[rndum] -- This picks a random map cmap:Destroy(cmap) cmap.Parent = workspace end
there are two problems I see and I hope I can help here they are:
-- first rndum on line 34 should be like this local rndum = math.random(1, #Maps) -- second and this should solve your problem is that when calling destroy you dont put anything in the brackets here is what it should look like: cmap:Destroy()