How can I get Coins to spawn in Random Locations

I don’t really understand what you’re talking about? But this is basically exactly what I am talking about.

Let’s say you have 2 positions, “699.21, 30.062, -5415.25”, and then “684.67, 30.062, -5435.845” How could I make it supposed to spawn within those 2 positions? Is there also a way to make there have a max amount of Coins so it doesn’t get laggy, and let’s say you get it 5 max, and it hits those 5 coins, if you collect a coin it will respawn, but since it’s at max it will NOT Respawn till another coin is collected. How can I do that?

1 Like

I literally just provided a script to achieve that.

Can you explain how I can edit it and get what I want? I don’t really see what to do… for the Spawn1, etc, what do I put, and make it that? A part, a Folder?

local spawncframes = {CFrame.new(699.21, 30.062, -5415.25), CFrame.new(684.67, 30.062, -5435.845)}
local rand = math.random(1, #spawncframes)
local coin = game.ServerStorage:WaitForChild("Coin")

while task.wait(10) do
	local coinclone = coin:Clone()
	coinclone.CFrame = spawncframes[rand]
	coinclone.Parent = workspace
end

If you still don’t get it then I can’t help.

Why does it do this?

What script are you using? How is everything organised in the explorer window?

This is pretty much what I did


I changed it to 1 for a test thingy

Because the user who replied decided to pick specified CFrames. Terrible method of doing it.

Here’s a perfect method on how to make your coins spawn in random positions.

ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries - Resources / Community Resources - DevForum | Roblox

That right there is a module called ZonePlus made by the one and only ForeverHD. What you would be doing is creating a folder for your zone, putting specific boundings for where you want your coins to spawn in the folder and then using the :getRandomPoint() function to get a random vector in your zone.

1 Like

I did that at his request though?

Yeah, that’s happening because there are only 2 possible spawn locations and you set the coins to spawn every second. Other than that the script works.

OP wanted it to spawn between the two positions, not at one or the other at random.

Well scattered around the 2 positions, like for example, how Pet Simulator X does it, or just any other game

local spawncframes = {CFrame.new(699.21, 30.062, -5415.25), CFrame.new(684.67, 30.062, -5435.845)}
local rand = math.random(1, #spawncframes)
local coin = game.ServerStorage:WaitForChild("Coin")

while task.wait(1) do
	local coinclone = coin:Clone()
	local randoms = math.random(-5, 5)
	coinclone.CFrame = spawncframes[rand] + CFrame.new(randoms, randoms, randoms)
	coinclone.Parent = workspace
end

Here, the coins will now scatter around those two spawn areas. I didn’t realise this was the behavior you wanted.

I’ve created an example for you, I dislike spoon feeding as it completely removes any point of me replying but whatever.

I’ll link you the API as well so you can do your own reading up.

Zone - ZonePlus (1foreverhd.github.io)

Here’s a basic coin spawning system. It won’t reward anything but it just instances new parts on a random position in a zone.

CoinSpawner.rbxl (65.5 KB)

Have a nice day/night.

1 Like


I seem to get this error? (I think I fixed it) Also how can I make it have a max Coins in that spot? Lets say 5 coins max in that area

It’s still going to spawn in a very limited position and in a real game will indeed look off.

local spawncframes = {CFrame.new(699.21, 30.062, -5415.25), CFrame.new(684.67, 30.062, -5435.845)}
local rand = math.random(1, #spawncframes)
local coin = game.ServerStorage:WaitForChild("Coin")

while task.wait(10) do
	local coinclone = coin:Clone()
	local random = math.random(-5, 5)
	coinclone.CFrame = spawncframes[rand]
	coinclone.Position += Vector3.new(random, random, random)
	coinclone.Parent = workspace
end

How can I make it spawn a Coin with scripts inside it, if you don’t mind answering.

You would used .Touched (make sure to destroy the connection afterwards of course) to detect when the coin has been touched. From there you would program it to add a number to a leaderstat and so on. There are tutorials for this on youtube by the way.

No no I mean for it to spawn a Coin that I already have, instead of the brick…