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

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
        coin.Position = Vector3.new(math.random(8, 89), 7.5, math.random(-99,0))
	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)

Try this code.

Shouldn’t “coin.Position = Vector3.new” go inside the for loop? It’s giving me red line under the word “coin” error.

change coin in coin.Position to coincc but keep it at its original place, which is inside of the first for loop where the coins are originally created.

1 Like

It says “Position is not a valid member of model workspace.coin.”

Can you send a screenshot of your code?

The coin is just a model not a part…

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
		coincc.Position = Vector3.new(math.random(8, 89), 7.5, math.random(-99,0))
	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)


```sorry, my screenshot tool isn't working.

@EgizianoEG told me that coincc is a model, which explains the error. To fix it, you can either take a part inside the model, and set the position of that, or you do coincc:MoveTo(position)

“Unable to cast double to Vector3” I have never gotten this before…

Try this code:

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


game.Players.PlayerAdded:Connect(function()
	local coins = {}
	for i = 1, 10 do
		local coincc = CoinCloned:Clone()
		coincc.Parent = workspace
		coincc:PivotTo(InitialCFrame)
		coins[i] = coincc
	end
	while true do
		task.wait(.01)
		for _, coin: Model in ipairs(coins) do
            local PositionCFrame = CFrame.new(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
			coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))
            coin:PivotTo(PositionCFrame)
		end
	end
end)

Your issue was that you’re passing a Vector3 to the PivotTo method without converting it to a CFrame

They just… keep teleporting around for some reason

I’m guessing that you want them to just spawn without changing their position after, right?

1 Like

That’s exactly what I want from this.

You’d need to move those lines to the first for loop and delete the existing PivotTo line in that loop.

	for i = 1, 10 do
        local PositionCFrame = CFrame.new(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
		local coincc = CoinCloned:Clone()

        coincc.Parent = workspace
        coincc:PivotTo(PositionCFrame)
        coins[i] = coincc
	end

Also, no need for the first two lines in the script…

so, like this?

local CoinCloned  = game:GetService("ServerStorage").Coin:Clone()


game.Players.PlayerAdded:Connect(function()
	local coins = {}
	for i = 1, 10 do
		local PositionCFrame = CFrame.new(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
		local coincc = CoinCloned:Clone()

		coincc.Parent = workspace
		coins[i] = coincc
	end
	while true do
		task.wait(.01)
		for _, coin: Model in ipairs(coins) do
			local PositionCFrame = CFrame.new(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
			coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))
			coin:PivotTo(PositionCFrame)
		end
	end
end)

You need to delete the first and third line in the second for loop or the coins would change its position.

The coins are all stuck in the same spot now :thinking: Im so confused lol

I mean that they are all in the same rotation and position as the original coin

It should not?
The for loop is generating a random CFrame every iteration, maybe try to print every CFrame generated to check if they are the same or something else happening…

@ZipMist, I just noticed that the PivotTo line was not included in the loop.

1 Like

Wait what? Can you re-type the whole script? I am so confused here.

Here is a rewritten one:

local CoinCloned  = game:GetService("ServerStorage").Coin:Clone()

game.Players.PlayerAdded:Connect(function()
	local coins = {}
	for i = 1, 10 do
        local PositionCFrame = CFrame.new(Vector3.new(math.random(8, 89), 7.5, math.random(-99,0)))
		local coincc = CoinCloned:Clone()

        coincc:PivotTo(PositionCFrame)    -- your missed line...
        coincc.Parent = workspace
        coins[i] = coincc
	end
	while true do
		task.wait(.01)
		for _, coin: Model in ipairs(coins) do
			coin:PivotTo(coin:GetPivot() * CFrame.Angles(0,.1,0))
		end
	end
end)
1 Like