How to make a part spawner that only spawns on one single base, but also randomly with maximum spawn?

So I’m making simulator and I need help with a random part spawner,
How to make a part spawner that only spawns on one single base, but also randomly with maximum spawn?

1gra

So example here my stage 1 is grass and i need to spawn it only on this part, but randomly, plus with a limit.

2 Likes

You could reference a couple of your own variables, encase it inside a while true do loop, then “Clone” the parts by putting them inside ServerStorage first, and then retrieving them using the Clone() function if there’s enough CurrentParts:

local PartLimit = 10
local CurrentParts = 0

while true do
    if CurrentParts < PartLimit then
        PartLimit += 1

        local RandomPosition = Vector3.new(math.random(-25, 25), 3, math.random(-25, 25))
        local PartClone = game.ServerStorage.toy1:Clone()
        PartClone.Parent = workspace
        PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
    end
    wait(1)
end

where do i put the script and is it local script or just script

1 Like

A script inside ServerScriptService would work just fine, just make sure to put what part you want to clone inside the ServerStorage for it to work

1 Like

1

is it like this i dont think it worked

That should work? If it didn’t, can you check your Output & see if there are any errors?

this is what it said

Um sir why do you have a virus in that script

Please remove the “Vaccine” script? Or check for any scripts that have getfenv inside them

o i get it is a npc i put it inside sorry let me try it again

it stil didnt work :.(

Try adding a couple of print() statements to it

local PartLimit = 10
local CurrentParts = 0
print("Running")

while true do
    print("Loop running")
    if CurrentParts < PartLimit then
        PartLimit += 1
        print("Cloning a part")
        local RandomPosition = Vector3.new(math.random(-25, 25), 3, math.random(-25, 25))
        local PartClone = game.ServerStorage.toy1:Clone()
        PartClone.Parent = workspace
        PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
    end
    wait(1)
end


i dont think the stuff appeared

Probably due to how the RandomPosition is set up

Increase the X, Y & Z values for those (X: -100, 100) (Y: 25) (Z: -100, 100)

is probly because of this right?

woo it worked but i think it only spawn not enough spaces can you make it spawn in the hole map?

but evrytime i make it to a cube, it disappear, please help

You could just divide the X & Z values by 2 for getting the total Part’s Size & where you want the clones to spawn inside the script when the Position is called for cloning a part

local PartLimit = 10
local CurrentParts = 0
local Grass = workspace["Stage 1"].grass
print("Running")

while true do
    print("Loop running")
    if CurrentParts < PartLimit then
        PartLimit += 1
        print("Cloning a part")
        local RandomPosition == Vector3.new(math.random(Grass.Position.X / -2, Grass.Position.X / 2), 10, math.random(Grass.Position.Z / -2 Grass.Position.Z / 2)) 
        local PartClone = game.ServerStorage.toy1:Clone()
        PartClone.Parent = workspace
        PartClone.Position = workspace["Stage 1"].grass.Position + RandomPosition
    end
    wait(1)
end

still dont work, there isnt spwan anthing

I think I did a dumb

Try this

local PartLimit = 10
local CurrentParts = 0
local Grass = workspace["Stage 1"].grass
print("Running")

while true do
    print("Loop running")
    if CurrentParts < PartLimit then
        PartLimit += 1
        print("Cloning a part")
        local RandomPosition == Vector3.new(math.random(Grass.Position.X / -2, Grass.Position.X / 2), 10, math.random(Grass.Position.Z / -2 Grass.Position.Z / 2)) 
        local PartClone = game.ServerStorage.toy1:Clone()
        PartClone.Parent = workspace
        PartClone.Position = RandomPosition
    end
    wait(1)
end