This MainScript is designed to spawn a "Template" after the player has touched "Landing2" and this will keep repeating after the player dies. (I shall repeat myself). A player would touch "Landing2" for the value in leaderstats to get +1 which is the "Sub-Level" and another "Template" would spawn and repeat and repeat, but then I realized that this was getting repetitive as now I want other rooms to spawn instead of the same "Template" spawning over and over again after the player touches "Landing2" and I'm having trouble randomizing it. please help.
Note: This game is supposed to be based on SCP-087 but I changed a couple of things like instead of SCP-087-1, I just replaced it with Gordon Ramsay and I just want it to spawn a few rooms in the stairwell instead of just stairs
Another note: I just putted here portions of the MainScript as it would be too long of a question.
local Players = require(game.ServerScriptService.LeaderBoardModule) game.Lighting.TimeOfDay = 0 local Template = workspace.Template local SubLevel = 1 local HeightOffset = Template:GetExtentsSize().Y - 4 local MinSPCShowAtLVLFromPlr = 5 local MaxSPCShowAtLVLFromPlr = 10 local SCP_Brain = script["SCP-087 Brain"]:Clone() local SummonedSCP = false local TemplateTble = {Total = 0} local Pad1 = {} local Pad2 = {} TemplateTble:init(Template) --[[ Clear our function out from the table so it's not included in the for loops below and break things ]] TemplateTble["init"] = nil local TemplateMiddlePart = (function() local Part = nil local TemplateBits = TemplateTble local SX = 0 local SY = 0 local SZ = 0 local CenterPoint = Vector3.new() for key,Obj in next, TemplateBits do if(key ~= "Total") then --print(key,Obj) if(Obj.Ref:IsA("BasePart") == true) then local X = Obj.Ref.Position.X local Y = Obj.Ref.Position.Y local Z = Obj.Ref.Position.Z SX = SX + X SY = SY + Y SZ = SZ + Z end end end SX = SX/TemplateBits.Total SY = SY/TemplateBits.Total SZ = SZ/TemplateBits.Total CenterPoint = Vector3.new(SX,SY,SZ) local Dist = math.huge for key,Obj in next, TemplateBits do if(key ~= "Total") then if(Obj.Ref:IsA("BasePart") == true) then local D = (CenterPoint - Obj.Ref.Position).magnitude if(D < Dist) then Part = Obj.Ref Dist = D end end end end return Part end)() function CreateNextLevel(newLevel) local YOffset = Template:GetExtentsSize().Y local Exists = workspace:FindFirstChild("Level_"..newLevel) ~= nil if(Exists == false) then -- Right if the level doesn't exist then lets create it!... local Clone = Template:Clone() for key,Tble in next, TemplateTble do if(key ~= "Total") then local Obj = Tble.Ref local CCopy_Part = Clone:FindFirstChild(key,true) if(CCopy_Part ~= nil) then CCopy_Part.Parent.Position = Obj.Position -Vector3.new(0,SubLevel*(YOffset-4.5),0) if(CCopy_Part.Parent.Name == "Landing2") then CCopy_Part.Parent.Touched:connect(function(otr) ConnectNewLevel(otr,CCopy_Part.Parent) end) end if(CCopy_Part.Parent.Name == "Landing1") then CCopy_Part.Parent.Touched:connect(function(otr) AddLevelToPlayer(otr,CCopy_Part.Parent.Parent) end) end end end end Clone.MyLevel.Value = SubLevel Clone.Name = "Level_"..SubLevel Clone.Parent = workspace SubLevel = SubLevel +1 end end workspace.Template.Landing1.Touched:connect(function(otr) local Player = otr.Parent AddLevelToPlayer(otr,workspace.Template) end) workspace.Template.Landing2.Touched:connect(function(otr) local Player = otr.Parent ConnectNewLevel(otr,workspace.Template.Landing2) end)