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)
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.
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)
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…
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)