Hello, I'm currently working on a script that, at the start of the game, will randomly select a model out of a table, clone it, move it to a new location, and do this 8 different times. When I join the game, this doesn't happen.
All models in the table exist and have primary parts. This script is in a part in workspace (supposed to act as the finish line). Here is my script:
local stages = {game.Workspace.Cars, game.Workspace["Split Jumps"], game.Workspace["Spinning Ladder"], game.Workspace["Truss Obby"], game.Workspace["Three Paths"], game.Workspace["Spinning Jumps"]}
local gametable = {}
local function generateStages()
for i = 1, 8, 1 do
table.insert(gametable, stages[math.random(1,#stages)])
end
local stage1 = gametable[1]:Clone()
stage1.Name = "Stage 1"
stage1:MoveTo(Vector3.new(-179, 155, 699))
local stage2 = gametable[2]:Clone()
stage2.Name = "Stage 2"
stage2:MoveTo(Vector3.new(-179, 155, 831))
local stage3 = gametable[3]:Clone()
stage3.Name = "Stage 3"
stage3:MoveTo(Vector3.new(-179, 155, 963))
local stage4 = gametable[4]:Clone()
stage4.Name = "Stage 4"
stage4:MoveTo(Vector3.new(-179, 155, 1095))
local stage5 = gametable[5]:Clone()
stage5.Name = "Stage 5"
stage5:MoveTo(Vector3.new(-179, 155, 1227))
local stage6 = gametable[6]:Clone()
stage6.Name = "Stage 6"
stage6:MoveTo(Vector3.new(-179, 155, 1359))
local stage7 = gametable[7]:Clone()
stage7.Name = "Stage 7"
stage7:MoveTo(Vector3.new(-179, 155, 1491))
local stage8 = gametable[8]:Clone()
stage8.Name = "Stage 8"
stage8:MoveTo(Vector3.new(-179, 155, 1623))
end
local function destroyStages()
game.Workspace["Stage 1"]:Destroy()
game.Workspace["Stage 2"]:Destroy()
game.Workspace["Stage 3"]:Destroy()
game.Workspace["Stage 4"]:Destroy()
game.Workspace["Stage 5"]:Destroy()
game.Workspace["Stage 6"]:Destroy()
game.Workspace["Stage 7"]:Destroy()
game.Workspace["Stage 8"]:Destroy()
end
generateStages()
local totalWins = Instance.new("IntValue")
totalWins.Parent = script.Parent
totalWins.Name = "Course Wins"
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("HumanoidRootPart")
if humanoid then
if totalWins < 1 then
totalWins = 1
hit.Parent.HumanoidRootPart.Position = game.Workspace.Spawner.Position
elseif totalWins == 1 then
totalWins = 0
hit.Parent.HumanoidRootPart.Position = game.Workspace.Spawner.Position
destroyStages()
wait(3)
generateStages()
end
end
end)

1 comment
Wow I can't believe I forgot that