Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The following script works and the map generates sometimes not all the times?

The map sometime generates randomly but doesn't other times, can I please get some help with the teleportation I used to store maps in lighting but now I switched it to ServerStorage.

01	-- Variables
02	 
03	    local player = game.Players:GetChildren()
04	 
05	    local maps = game.ServerStorage.Maps:GetChildren()
06	 
07	    local currentmap = game.Workspace:WaitForChild("CurrentMap")
08	 
09	    local chosenmap = script:WaitForChild("ChosenMap")
10	 
11	    local spawner = game.Workspace:WaitForChild("Spawn")
12	 
13	    local choices = {}
14	 
15	    function choosemap()
16	 
17	    for i = 1,#maps do
18	 
19	    if maps[i]:isA("Model") then
20	 
21	    table.insert(choices,maps[i])
22	 
23	    local picked = math.random(1,#maps) chosenmap.Value = choices[picked].Name
24	 
25	           end
26	       end
27	    end
28	 
29	    function loadmap()
30	 
31	    local map = game.ServerStorage.Maps:FindFirstChild(chosenmap.Value)
32	 
33	    map:Clone().Parent = currentmap
34	 
35	    end
36	 
37	    function deleteMap()
38	 
39	    for i,v in pairs(currentmap:GetChildren()) do
40	 
41	    if v:isA("Model") then
42	 
43	    v:Destroy()
44	 
45	          end
46	       end
47	    end
48	 
49	 
50	    function teleportPlayers()
51	 
52	    for i,v in pairs() do
53	 
54	    v.Character:FindFirstChild("HumanoidRootPart").CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn * CFrame.new(math.random(5,10),0,math.random(5,10))
55	 
56	       end
57	    end
58	 
59	    function teleportBack()
60	 
61	    for i,v in pairs(player) do
62	 
63	    v.Character:FindFirstChild("HumanoidRootPart").CFrame = spawner.Spawnlocation.CFrame* CFrame.new(math.random(5,10),0,math.random(5,10))
64	 
65	    end
66	 
67	    end
68	 
69	    while true do
70	 
71	    wait(3)
72	 
73	    choosemap()
74	    loadmap()
75	    wait(1)
76	    teleportPlayers()
77	    wait(10)
78	    deleteMap()
79	    teleportBack()
80	 
81	    end

2 comments

0

One thing, put your 'local picked = math.random(1,#maps) chosenmap.Value = choices[picked].Name' above the end for 'choosemap()'.

0

So put line 23 above line 15?

1 answer

Its probably because you have all the numbers there.

This discussion is preserved as it was. New answers, comments, and votes are closed.