I have created this script for a game, it randomly moves rooms that I have created and placed in Replicated Storage (in a folder called GeneratedRooms), to placeholder floors in the workspace (in a folder called PlaceHolders). To create a tunnel of randomly generated rooms.
The Script:
local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren() for I, placeHolder in pairs (game.Workspace.PlaceHolders:GetChildren()) do local chosenRoom = rooms[math.random(1,#room)]:Clone() chosenRoom.PrimaryPart = chosenRoom.Floor chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame) placeHolder:Destory() chosenRoom.Parent = game.Workspace end
I was wondering how I could make this script be able to reset its self every few minutes, so it has a new set of randomly generated rooms. Currently, I have to leave and rejoin the game to get a different set of rooms.
Thanks for your help!
Just put it in a loop that only runs every so often
--First of all you will need a way to reset the rooms that were already in place local rooms = Instance.new("Folder") -- Create new folder to store the rooms in rooms.Name = "Rooms" rooms.Parent = workspace local timer = 60 -- Change 60 to however many seconds you want to wait inbetween room changes while true do rooms:ClearAllChildren() -- Removes all previous rooms local rooms = game.ReplicatedStorage:WaitForChild("GeneratedRooms"):GetChildren() for I, placeHolder in pairs (game.Workspace.PlaceHolders:GetChildren()) do local chosenRoom = rooms[math.random(1,#rooms)]:Clone() -- You had it set to #room? I think you meant to have it as #rooms. That just says to choose an index between 1, and the number of items in the table. chosenRoom.PrimaryPart = chosenRoom.Floor chosenRoom:SetPrimaryPartCFrame(placeHolder.CFrame) placeHolder:Destory() -- Not sure about this, if you destroy the place holders you wont have any to set the next rooms at. But I have no idea what you have going on as placeholders, if they are just invisible parts just set them to cancollide false so you can keep using them chosenRoom.Parent = rooms end wait(timer) end -- You may also want to move the player so he doesnt fall to his death when old rooms are destroyed, in that case just use character.HumanoidRootPart.CFrame = SpawnPart.CFrame * CFrame.new(0,3,0) before you :ClearAllChildren()
You could make it so the script has a duplicated version of the script that is disabled and has a different name in lighting and you could copy it into ServerScriptService For example:
local a = lighting.DupeScript while true do wait(interval) a:Clone().Parent = workspace workspace.DupeScript.Name = "OGScript" wait(0.1) ServerScriptStorage.OGScript:Destroy() wait(0.1) workspace.OGScript.Parent = ServerScriptStorage wait(0.1) ServerScriptStorage.OGScript.Disabled = false end This is the only thing I could think of, hope it helps!