Random spawn for coin not working

Okay so, there is a script that spawns a coin from replicatedstorage into the workspace in a folder.

The script does work and duplicates a coin, but when it works again it moves/deletes the old coin and puts it in a new position so no more than 1 coin can be present, does anyone know why this is the case?

The script:

while wait(4) do
	local coin = game.ReplicatedStorage.Coins:WaitForChild("World1")
	local coins = game.Workspace.Coins
		local a = math.random(-63,48)
		local b = math.random(-32,40)
		coin:Clone()
		coin.Parent = game.Workspace.Coins.World1
		coin.Position = Vector3.new(a,2.314,b)
		coin.Script.Disabled = false

end

**EDIT
The coin comes out of replicatedstorage space. How do i keep it in replicated storage?

1 Like

you are actually get the coin for repStorage, instead make this

local coinClone = coin:Clone()

then just change ur coin to coinClone

Ohhh thank you :slight_smile: ill give it a test now

Yes, as stated above, don’t change the parent clone it, so,
local coinClone = coin:Clone()
coinClone.Parent = workspace

while wait(x) do
  ...
end

Is bad practice

1 Like

@LukaDev_0
How so?

@DevParallax
Thank you i now see where i went wrong im trying to parent the item thats in replicatedstorage

try this:

while wait(4) do
	local coin = game.ReplicatedStorage.Coins:WaitForChild("World1")
	local coins = game.Workspace.Coins
		local a = math.random(-63,48)
		local b = math.random(-32,40)
		local coinCopy = coin:Clone()
		coinCopy.Parent = game.ReplicatedStorage
		coinCopy.Position = Vector3.new(a,2.314,b)
		coinCopy.Script.Disabled = false

end

if you want the coins to spawn in workspace just change their parent

1 Like