uhh…
Uhh…
I wanted to spawn borders around a specfic area that’s randomized
but when i place borders with scripts they stack on the same position or it only spawns one and then changes position forever not allowing the other 2 rows to spawn…
i’ve made a quick schematic to visualize what i mean…
so as you can see each cube is 32x1x32 in size.
the green parts are how the cube Should be spawning , the red parts are the stacking problem where alot of the cubes just spawn in eachother until there are 50 and then it moves to the orange code, orange means it just spawns 1 and then just yields infinite and the other 2 green rows never even appear…
now i have found a few things which could be the reason behind it.
first below here i will show some functions and variables so you can see how im spawning my stuff…
in the function CheckIfOccupied, i tried to check if the position gets added to the usedpositions table which holds the used psoitions so the script would loop through there and if any matches the current chosen one it would change it with 32 on x axis or z depending on which border is being made.
then it would check again if it wouldn’t match (return nothing) it would spawn a border there and check again (obviously it already just placed a border there so it would return true and add 32)
but what is really happening is that instead for the red ones it always goes in the same position (always returns nothing) and for the orange ones it places one then always returns true.
because of this after orange nothing gets placed and everything that should’ve come after orange never happens…
here are the code pieces i am talking about:
local function CreateBorders()
print("First!")
local BorderPosition = ClassicPos + Vector3.new(0,0,-32)--1568, 14(7?), 256 --Don't Multiply Saves!
AmountOfRoomsX = RoomIncrement
BorderRow(BorderPosition)--Nil Problem Needs Fixing!
BorderPosition = PositionZ --Works!
print("Second!")
AmountOfRoomsX = RoomIncrement
BorderRow(BorderPosition)--MOVES indefintely!
BorderPosition = ClassicPos + Vector3.new(-32,0,0)
print("Third!")
AmountOfRoomsX = 10--500/50 = 10
BorderRowAlternate(BorderPosition)
BorderPosition = PositionX
print('Fourth!')
AmountOfRoomsX = 10
BorderRowAlternate(BorderPosition)
end
local function BorderRow(BasePos: Vector3?)
local UsingPos = BasePos
repeat
if CheckIfOccupied(UsingPos) then
UsingPos = UsingPos + Vector3.new(32,0,0)
else
SpawnBorders(UsingPos)
AmountOfRoomsX -= 1
end
wait(WaitTime)
until AmountOfRoomsX <= 0
end
local function SpawnBorders(Pos: Vector3?)
local RandomBorder = math.random(1,#Borders)
for i,v in pairs(Borders) do
if i == RandomBorder then
if v:IsA("Model") then
local Clone = v:Clone()
Clone.Parent = workspace
Clone:PivotTo(CFrame.new(Pos))
end
end
end
table.insert(UsedPositions,Pos)
end
local function CheckIfOccupied(Pos: Vector3?)
for i,v in pairs(UsedPositions) do
if v == Position then
return true
end
end
end
local Borders = game.ReplicatedStorage.Borders:GetChildren()
local AmountOfRooms = 50
local AmountOfRoomsX = 50
local RoomIncrement = 50--idk why i named it that just act like its called something else
local Position = Vector3.new(0,7,0)--the current xyz axis the script is placing borders at
local PositionZ = Vector3.new(0,7,0)--the current z coordinate the scrip is placing blocks at
local PositionX = Vector3.new(0,7,0)--the current x coordinate the script is placing blocks at
local ClassicPos = Vector3.new(0,7,0)--where the script placed its first border
those variables above this text are used to uhh (is it called calculate?) “calculate” where the borders should spawn, and they do work the placement where the row starts is perfect but then the errors appear and i’ve been trying to solve it myself and some help of the devforum (without revealing too much of my plan because idk i don’t like people seeing what i do) but when i saw they solved the small problem like it prints nil but not the bigger problem i knew i had to reveal much more.
uhh hope you don’t fall asleep by reading this…
thanks in advance?
