local Buildings = game.replicatedstorage.Structures:GetChildren()
function AssignToPlots(GridX,GridY,Buildings)
local grid = {}
for i = 1,#GridX do
for i2 =1,#GridY do
Grid[GridX,GridY] = Buildings[math.random(1,#Buildings)]
end
end
end
So this example would put the buildings inti a grid format so you can load them to the correct positions
All that would be left is actually cloning the models and change the randomising to be chance.
My script does not seem to work, this is what it looks like now:
local Buildings = game.ReplicatedStorage.Plots:GetChildren()
function AssignToPlots(GridX,GridY,Buildings)
local grid = {}
for i = 1,#GridX do
for i2 =1,#GridY do
grid[GridX, GridY] = Buildings[math.random(150, #Buildings)] -- There is a error here.
end
end
end
AssignToPlots(game.Workspace.GridX, game.Workspace.GridY)
The error is that you put 150 into math.random, math.random picks a random number between the first number given and the second. So #buildings is the second number as putting a hash before a variable containing a list will actuall give you the number of items in the list. So rather than 150 put 1
It is a good topic, but it does not fit my game. My game is split up into plots, like let’s say we have a table plot, kitchen and living room plot. The system would randomly generate out of those. That is what I am trying to say, sorry!
maybe something like this can help you get started
local seed = nil -- if the seed is nil then it will be a random seed
local rand = Random.new(seed)
local chunks = game.ReplicatedStorage.Chunks:GetChildren()
local chunkSpacing = 16
for x = -10, 10 do
for z = -10, 10 do
-- select a random chunk model
local i = rand:NextInteger(1, #chunks)
-- clone the random chunk
local clone = chunks[i]:Clone()
-- position the clone chunk
clone:PivotTo(CFrame.new(x * chunkSpacing, 0, z * chunkSpacing))
-- parent the clone
clone.Parent = workspace
end
end
or if you want the chunks to be spawned at parts
local seed = nil -- if the seed is nil then it will be a random seed
local rand = Random.new(seed)
local chunks = game.ReplicatedStorage.Chunks:GetChildren()
for i, part in ipairs(workspace.Folder:GetChildren())
-- select a random chunk model
local i = rand:NextInteger(1, #chunks)
-- clone the random chunk
local clone = chunks[i]:Clone()
-- position the clone chunk
clone:PivotTo(part.CFrame)
-- parent the clone
clone.Parent = workspace
end
Does not seem to work, my script is in Workspace and it is a server-side Script.
Script:
local seed = nil -- if the seed is nil then it will be a random seed
local rand = Random.new(seed)
local chunks = game.ReplicatedStorage.Generation
local chunkSpacing = 11
for x = -10, 10 do
for z = -10, 10 do
-- select a random chunk model
local i = rand:NextInteger(1, #chunks)
-- clone the random chunk
local clone = chunks[i]:Clone()
-- position the clone chunk
clone:PivotTo(CFrame.new(x * chunkSpacing, 0, z * chunkSpacing))
-- parent the clone
clone.Parent = game.Workspace
end
end
Only localscripts don’t run when you put them in the workspace so if it’s a localscript then you have to put it into starterplayerscripts or replicatedfirst
The script is not disabled, not sure why this is not working. When I was testing I was using the Run feature in the testing menu, maybe that info will help.