im trying to make a system where when you touch pivot or the end part of a stage, it would spawn a new stage after it which is essentially infinite. but instead of the next part spawning new stages, only the first end part/pivot would trigger it
i tried using ai and it worked but the code seems to complicated for m level of understanding and I would not want to use AI in my games
--
local storage = workspace.ObbyStagesStorage
local children = storage:GetChildren()
local pivot
--
local function getRandomStage()
local index = math.random(1, #children)
return storage[index]
end
local function getNewStage()
local chosen = getRandomStage()
local newStage = chosen:Clone()
newStage:PivotTo(pivot.CFrame)
newStage.Parent = workspace
pivot = newStage.EndPart
return pivot
end
--
local debounce = true
local function onPivotTouched(hit)
if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
getNewStage()
pivot = getNewStage()
debounce = false
else
task.wait(2)
debounce = true
end
end
--
pivot = workspace.Spawn.EndPart
pivot.Touched:Connect(onPivotTouched)
this is how it looks like in game