I got the idea to reply to keep it alive, so I don’t have to make a bunch of new posts because no one, out of the 41 views on this, has replied… Not 1 reply.
local X, Z = 11, 11
local LastChunk = nil
local Tick = 0
local Segment = {}
Segment.__Index = Segment
function Segment.new(SegmentPosX, SegmentPosZ)
local SEGMENTS = {
s1 = script.Segment1,
s2 = script.Segment2,
s3 = script.Segment3,
s4 = script.Segment4,
s5 = script.Segment5,
s6 = script.Segment6,
s7 = script.Segment7,
s8 = script.Segment8
}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
while char.Humanoid.Health > 0 do
task.wait()
if LastChunk == nil or (LastChunk.Position - char.HumanoidRootPart.Position).Magnitude <= 15 then
local segmentToUse = math.random(1, 8)
local segmentCopy
if segmentToUse == 1 then
segmentCopy = SEGMENTS.s1:Clone()
elseif segmentToUse == 2 then
segmentCopy = SEGMENTS.s2:Clone()
elseif segmentToUse == 3 then
segmentCopy = SEGMENTS.s3:Clone()
elseif segmentToUse == 4 then
segmentCopy = SEGMENTS.s4:Clone()
elseif segmentToUse == 5 then
segmentCopy = SEGMENTS.s5:Clone()
elseif segmentToUse == 6 then
segmentCopy = SEGMENTS.s6:Clone()
elseif segmentToUse == 7 then
segmentCopy = SEGMENTS.s7:Clone()
else
segmentCopy = SEGMENTS.s8:Clone()
end
if LastChunk ~= nil then
local offset = CFrame.new(0 ,0, (segmentCopy.Size.Z/2) + (LastChunk.Size.Z/2) )
segmentCopy.CFrame = LastChunk.CFrame:ToWorldSpace(offset)
LastChunk = segmentCopy
else
segmentCopy.Position = Vector3.new(char.HumanoidRootPart.Position.X, 0.5, char.HumanoidRootPart.Position.Z)
LastChunk = segmentCopy
end
segmentCopy.Parent = workspace.Backrooms
end
end
end)
end)
end
return Segment
This is the custom way I think of procedural generation, you can use the check magnitude thing later on to destroy or put away the segments, in this case I used plain parts so if you have models you’d use their primaryparts and define a new floor position which I had mine set as 0.5.
It generates only in Z direction though but it should give a brief idea of how you could go about it.
I had another code that did just this, but when I tried to generate it in the X direction at the same time, the X was offset, which is why I was trying to get everything to generate at once.
I’ll try to combine it will the X direction and see if it actually works this time.
You could use raycast function to check each block on X and if it returns nothing then generate block on the right/left of that block
If you wish to have like lets say 2 bricks on each side then have a variable that says current amount generated for the current segment’s side and if its up to par move onto next brick
The LastChunk variable needs to be there as to determine if the last chunk has been loaded, otherwise the code will just run an infinite loop and possibly crash you
People aren’t able to help you because your code relies on the segment objects in your game, making it hard to work with. Maybe you could provide a place file to give people more insight into the project.
Noclipped…rbxl (49.3 KB)
Here is the file, the segments are under the baseplate
Also why would you need the game file anyway? It’s just equivalent to having 30x30 parts generate in chunks just a flat plane.
I don’t recommend trying to run it in it’s current state
Sorry, took a while since I was occupied with one of my own projects, but here’s my fixed version of the place file you sent me. I had to redesign the segments to make them work with chunk generation, but luckily they’re just models, so you can alter them if needed. Also improved the way segments are handled, so that you don’t have to manually add them to a table. Just parent them to the script like you did before and it will work. I basically had to heavily expand and overhaul the whole scripting part since most of the functionality needed for chunk generation was either missing or not working as intended. You can take a look at the place file and tell me if that fits your needs.