You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
im trying to make a backrooms-ish style game to mess around with my friends in
that has smooth random section generation around the players
(infinite)
- What is the issue? Include screenshots / videos if possible!
ive got it somewhat working but its SO LAGGY
and when i turn the loop speed down to just a task.wait() it crashes the studio
How would i fix this?
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
slowing down the loop does work when your first starting out, but it wont really matter when you play for longer as it has to loop through LOTS of generated Sections
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
modules code
local module = {}
local function RandomSection()
local Sections = script.Sections:GetChildren()
return Sections[math.random(1, #Sections)]
end
local function HasTag(Obj,TagName)
for i,v in pairs(Obj:GetTags()) do
if v == TagName then
return true
end
end
return false
end
local function InverseVector(Vec)
local New
local x,y,z
if Vec.X ~= 0 then
x = -Vec.X
else
x = 0
end
if Vec.Y ~= 0 then
y = -Vec.Y
else
y = 0
end
if Vec.Z ~= 0 then
z = -Vec.Z
else
z = 0
end
return Vector3.new(x,y,z)
end
module.Generate = function(From)
local CollectionService = game:GetService("CollectionService")
local function Create(offset)
if not HasTag(From,("Generated"..tostring(offset))) then
CollectionService:AddTag(From,"Generated"..tostring(offset))
local Section = RandomSection():Clone()
Section:PivotTo(From.PrimaryPart.CFrame+offset)
Section:PivotTo(CFrame.new(Section.PrimaryPart.Position)*CFrame.fromEulerAnglesXYZ(0,0,0))
Section.Parent = workspace.GeneratedRooms
CollectionService:AddTag(Section,"Generated"..tostring(InverseVector(offset)))
end
end
CollectionService:AddTag(From,"Generated")
Create(Vector3.new(0,0,From.PrimaryPart.Size.Z))
Create(Vector3.new(0,0,-From.PrimaryPart.Size.Z))
Create(Vector3.new(From.PrimaryPart.Size.X,0,0))
Create(Vector3.new(-From.PrimaryPart.Size.X,0,0))
end
module.TrackRange = function(Part)
local Range = 100
while task.wait() do
if Part then
for i,v in pairs(workspace.GeneratedRooms:GetChildren()) do
if (Part.Position-v.PrimaryPart.Position).Magnitude < Range and not HasTag(v,"Generated") then
module.Generate(v)
end
end
else
break
end
end
end
return module
the place file:
GENERATION.rbxl (58.0 KB)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.