thats the script
What i want to do is when a timer goes up, it will reset the generator script and generate another map. kinda like tower of hell map generation.
If you need any clarification, just ask
There’s a few ways this could be done, but what I usually do is create a ModuleScript which has the functionality for managing rooms (I assume that’s something you need?), and then a regular script to respond to events/triggers and then call said ModuleScript.
For example:
-- ModuleScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PossibleHallways = ReplicatedStorage:WaitForChild("Possible Hallways")
local GeneratedRooms = workspace:WaitForChild("Generated Rooms")
local module = {}
function generateRoom()
-- Your "GenerateRoom" function here
end
function module.GenerateRooms(numRooms: number) -- "numRooms: number" means that the variable numRooms is expected to be of type "number"
for i=1, numRooms do
generateRoom()
end
end
function module.ClearRooms()
GeneratedRooms:ClearAllChildren() -- Remove all rooms
end
return module
-- Script
local RoomManager = require(<path>) -- Replace with path to the above modulescript
local restartEvent = <path> -- Create a BindableEvent which is triggered whenever you want the rooms to reset.
function restart()
RoomManager.ClearRooms()
RoomManager.GenerateRooms(10)
end
restart() -- Instantly populate
restartEvent.Event:Connect(restart) -- Restart whenever the event is triggered
I might have understood something incorrectly, please let me know if I did!
On a side note:
When sending code here, I would recommend doing what I did instead of sending images (if possible). You add code by doing: “```” before and after it. Ex:
```
– Example comment
local myVar = 3
print(myVar)
```
The above creates the following:
I think you forogt the start point thing
`local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local PossibleHallways = ReplicatedStorage:WaitForChild(“Possible Hallways”)
local GeneratedRooms = workspace:WaitForChild(“Generated Rooms”)
prevRoom = workspace.StartPoint
local numRooms = 10 --// NUMBER OF ROOMS YOU WANT
function generateRoom()
local randomroom = PossibleHallways:GetChildren()[math.random(1, #PossibleHallways:GetChildren())]
local clonedroom = randomroom:Clone()
I think you forogt start point
"’
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local PossibleHallways = ReplicatedStorage:WaitForChild(“Possible Hallways”)
local GeneratedRooms = workspace:WaitForChild(“Generated Rooms”)
prevRoom = workspace.StartPoint
local numRooms = 10 --// NUMBER OF ROOMS YOU WANT
function generateRoom()
local randomroom = PossibleHallways:GetChildren()[math.random(1, #PossibleHallways:GetChildren())]
local clonedroom = randomroom:Clone()
Almost, it has to be these: `. For me it is located next to “?”. In the preview of your post it will look like the code, so that’s how you know it is the right one.
And yes, I didn’t write out everything. But to add what your existing code all you need to do is this:
-- ModuleScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PossibleHallways = ReplicatedStorage:WaitForChild("Possible Hallways")
local GeneratedRooms = workspace:WaitForChild("Generated Rooms")
local module = {}
local prevRoom = workspace.StartPoint
function generateRoom()
local randomroom = PossibleHallways:GetChildren()[math.random(1, #PossibleHallways:GetChildren())]
local clonedroom = randomroom:Clone()
clonedroom.PrimaryPart = clonedroom.Exit
clonedroom:PivotTo(prevRoom.Entrance.CFrame)
clonedroom.Parent = GeneratedRooms
clonedroom.Entrance.Transparency = 1
clonedroom.Exit.Transparency = 1
prevRoom = clonedroom
end
function module.GenerateRooms(numRooms: number) -- "numRooms: number" means that the variable numRooms is expected to be of type "number"
for i=1, numRooms do
generateRoom()
end
end
function module.ClearRooms()
prevRoom = workspace.StartPoint -- Reset startpoint
GeneratedRooms:ClearAllChildren() -- Remove all rooms
end
return module
Path is the location of the ModuleScript, just like how you find your StartPoint.
If you name the ModuleScript “RoomManager”, and put it under “ServerStorage”, then in the script you would access the modulescript using:
local RoomManager = require(game:GetService("ServerStorage"):WaitForChild("RoomManager"))
The “<” and “>” I wrote earlier is not actually in the path, it is just stuff added to show that what is written is just an explanation placeholder, and that the entire text (including the arrows) should be replaced with what is described.
I have made the changes it should look liek this right?
local RoomManager = require(script.ModuleScript) -- Replace with path to the above modulescript
local restartEvent = -- Create a BindableEvent which is triggered whenever you want the rooms to reset.
function restart()
RoomManager.ClearRooms()
RoomManager.GenerateRooms(10)
end
restart() -- Instantly populate
restartEvent.Event:Connect(restart) -- Restart whenever the event is triggered
type or paste code here