How can I make a part spawn randomly like a coin spawner

Nope, it happens even if I try it inside the game or by running and deleting them one by one

Well, you can make it simpler if the object doesn’t change size, no need to make the script divide.

newStuff.Position = Floor.Position + Vector3.new(math.random(-Floor.Size.X/2, Floor.Size.X/2), 5 ,math.random(-Floor.Size.Z/2, Floor.Size.Z/2))

Well the Floor Size divide 2 one is just to make the part exactly in the floor, what I meant is that the part will not go outside of the floor

Yeah it’s good for every situation but you can make it simpler just by taking the size of the floor and divide it by 2 with a calculator instead of making the script divide by 2 every time.

I don’t want to waste my time on a calculator, I usually will make math dividing stuff or blah blah blah

This can mean that if there’s as much things as the max capacity of things a thing will still spawn

I forgot about to change to that lol.

if HowManyStuffsInFolder <= MaxCapacity then

Should’ve changed to

if HowManyStuffsInFolder < MaxCapacity then

What do you mean by break? An extra thing appears? There’s an error in the console?
If an extra thing appears we fixed the problem.

It just break the script, he said that.

Pretty sure this one will work

local Floor = workspace:FindFirstChild("CoinSpawnFloor1")
local StuffOrSomethingIDK = script:FindFirstChild("HealthGem")-- Change the "Your Desired Part" to your desired "part" I guess

local WaitTime = 2 -- How long it will take to spawn another stuff
local HowManyStuffs = 2 -- How many stuffs you want its to spawn
local MaxCapacity = 5 -- How many stuffs can it hold

local HowManyStuffsInFolder = 1 -- Set it to 1

while task.wait(5) do -- Remove the While Loop if you don't want it looping over and over again
	for i = 1, HowManyStuffs do
		local YourFolder = workspace:FindFirstChild("Boss1Health")
		HowManyStuffsInFolder = #YourFolder:GetChildren() -- Gives number { DON'T DELETE }
		
		if HowManyStuffsInFolder < MaxCapacity then
			local newStuff = StuffOrSomethingIDK:Clone()
			newStuff.Position = Floor.Position + Vector3.new(math.random(-Floor.Size.X/2, Floor.Size.X/2), 5 ,math.random(-Floor.Size.Z/2, Floor.Size.Z/2)) -- Make it exactly on the floor 
			newStuff.Parent = YourFolder

			task.wait(WaitTime)
		else
			break
		end
	end
end
3 Likes

Break like after one part is deleted after reaching the capacity, other part doesn’t spawn at all

I would do something like this:

local floorHalfSize = 0 --put the half size of the floor here
--ect
newStuff.Position = Floor.Position + Vector3.new(math.random(-floorHalfSize, floorHalfSize), 5 ,math.random(-floorHalfSize, floorHalfSize)) --this only works if the floor is a square on X-Z

Let’s Go!! This Is Working Perfectly!!

I’m too lazy to do that, unless the game is in my Work In Progress list.

Thanks @nontoxicguy1 and @BirdieGoodMan For Helping Me With This Weird Still Time Taking Issue, Your Help And Contribution Is Appreciated A Lot!

1 Like

Don’t forget to mark the solution when you’re finally found the solution.

1 Like

Thanks, but he did most of the work I totally accept that he gets the answer

2 Likes

I just realised this, bro :skull:

2 Likes

Didn’t want to delete it, so I just added that lol :skull:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.