-
I want my procedural track generation to yield until replacement tracks have been made
-
The issue is caused by more tracks trying to generate while it itself is regenerating
…causing track IDs to get skipped
Here’s what currently relates to the issue (regenerating, and how the iteration works)
Culprit code snippet #1
local hitbox = chosenTrack:FindFirstChild("Hitbox") --BasePart
local touching = hitbox:GetTouchingParts()
hitbox.Touched:Connect(function() end) --not pretty but its needed for gettouchingparts
for _, i in touching do
if i.Parent ~= chosenTrack or i.Parent ~= lastTracks[1] then
chosenTrack:Destroy()
workspace.generatedTracks[iteration-1]:Destroy()
warn("Retrying.. Track #"..iteration.." intersected something")
print("Regenerating as "..iteration-1)
local newtr = {workspace.generatedTracks[iteration-2],-1}
return newTrack:Generate(newtr,iteration-1)
end
end
Culprit code snippet #2
local trackNumber = math.random(650,1700)
local trackScript = require(script.trackscript) --referring to the ModuleScript Culprit #1 is found in
local prevTrack = {workspace.starttrack,1}
local constants = game:GetService("ServerStorage").constantspawns
print("TRACKS: "..trackNumber)
local iteration = 0 --stored outside function
for i=1, trackNumber+1 do --trackNumber+1 to track when course should end, removed for debugging
if prevTrack[2] ~= nil then
iteration +=prevTrack[2] --add or subtract, depends what returns
print("Generating track "..i)
end
wait(.1) --Issue occurs here, I can't figure out how to make it yield to respect the ModuleScript
prevTrack = trackScript:Generate(prevTrack,iteration)
end
Any help relating to my issue would be greatly appreciated