How would I make a model that clones 10 times for every player?

I need to create a coin that clones itself 10 times for every player. I am hoping to make it so that they can pick up the coin and it gives them 1 gold.

My issue is that It isn’t cloning itself 10 times. Only once.

I have already tried looking for possible solutions and I have not found any. Any help is appreciated.

This is my code so far:

local position = Vector3.new(math.random(8, 89), 7.5, math.random(-99,0))
local cf = CFrame.new(position)
local coinclone  = game:GetService("ServerStorage").Coin:Clone()



	
	
	
game.Players.PlayerAdded:Connect(function()
	local coincc = coinclone:Clone()
	
	coincc.Parent = workspace
	coincc:PivotTo(cf)
	while true do
		wait(.01)
		coincc:PivotTo(coincc:GetPivot() * CFrame.Angles(0,.1,0))
	end
end)
1 Like

You can do this with repeat

local clones = 0
repeat
coincc:Clone()
clones += 1
until
clones == 10

Would it not be easier to use a for loop instead?

for i = 0,10,1 do
     coincc:Clone() 
end

Also, you should include the random position variable and the CFrame inside of this loop, Otherwise, that random position will only be generated once, and all 10 coins will be moved to that exact same position. By moving the position inside the loop, all 10 coins will be moved to different, randomized positions.

1 Like

You can use a for loop for this.

game.Players.PlayerAdded:Connect(function()
	local coins = {}
    for i = 1, 10 do
        local coincc = coinclone:Clone()
        coincc.Parent = workspace
        coincc:PivotTo(cf)
        coins[i] = coincc
    end

	while true do
		task.wait(.01)
        for _, coin in ipairs(coins) do
            coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))
        end
	end
end)

Hmm. This doesn’t seem to work. I have tried implementing this in a few different ways though.

Did you get an error or something?!

nope, nothing… nothing is working yet. :frowning:

Alright, what is the part that is not working? Is the coin being cloned and parented to the wrokspace?

Yes, I had just noticed something. They’re all in the same position! This is the reason I didn’t see them. I need help now, trying to get them to spawn in different locations around the map…

You can move the position and cframe variables inside the for loops…

This is what happens when I run the game.

Let me try to code this now. Thanks for the idea!

1 Like

image

local position = Vector3.new(math.random(8, 89), 7.5, math.random(-99,0))
local cf = CFrame.new(position)
local coinclone  = game:GetService("ServerStorage").Coin:Clone()


game.Players.PlayerAdded:Connect(function()
	local coins = {}
	for i = 1, 10 do
		local coincc = coinclone:Clone()
		coincc.Parent = workspace
		coincc:PivotTo(cf)
		coins[i] = coincc
	end

	while true do
		task.wait(.01)
		for _, coin in ipairs(coins) do
			coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))
			coin:PivotTo(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
		end
	end
end)

I need some more info on this lol

Your problem is with coin:PivotTo(Vector3.new. You are supposed to pass a CFrame, not a Vector3. You can try replacing Vector3.new with CFrame.new

Doing this just makes them teleport really fast

but at least they are in different positions

I noticed you are using PivotTo twice? why is that?

oh, do you mean in

coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))

this is to rotate the coin forever.

coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))

Then what is the line immediately after it for?

To change it’s position, I’m fairly sure that’s how it works. If I’m wrong please do not hesitate to correct me.