Hello! How can I make a Script, that makes Coins spawn around the map? 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?
local spawncframes = {CFrame.new(0, 0, 0), CFrame.new(50, 50, 50)}
local rand = math.random(1, #spawncframes)
local coin = game.ServerStorage:WaitForChild("Coin")
local coins = {}
while task.wait(10) do
if #coins <= 10 then --less than or equal to 10 active coins
local coinclone = coin:Clone()
local randoms1 = math.random(-15, 15)
local randoms2 = math.random(-15, 15)
local randoms3 = math.random(-15, 15)
coinclone.Name = "Coin"
coinclone.CFrame = spawncframes[rand]
coinclone.Position += Vector3.new(randoms1, 0, randoms3)
coinclone.Orientation = Vector3.new(0, 0, 0)
coinclone.Parent = workspace
coinclone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
coinclone:Destroy()
end
end)
coins = {}
for i, v in pairs(workspace:GetChildren()) do
if v.Name == "Coin" then
table.insert(coins, v)
end
end
end
end
If you need any assistance understanding anything let me know.