I'm still a bit rusty after finally coming back to Lua, so I expect it's an easy fix and an obvious error.
As of now, this script will copy the specified model, move it to the correct parent, and then just move that one model around randomly within 1 block of a random point instead of randomly around the whole area. I assume that's because it takes the same random number first iterated, but also have a hunch I may just need to use seeds.
But, the largest issue here is that it only copies one model and moves it for the iterated amount of times. I'm pretty sure it's because I used an iteration without renewing it, but I'm not sure.
I just copied the relevant part of the code, so if there are any missing variables, just let me know and I can add them. Thank you!
local x = script.Parent.Position.X; local y = script.Parent.Position.Y - 5; local z = script.Parent.Position.Z; local copper = game.Lighting.oretotal.Copper; local cclone = copper:Clone(); local Bounds = { {x1=x-xhalf,x2=x+xhalf}, {z1=z-zhalf,z2=z+zhalf} } local boundsrandx = math.random(Bounds[1].x1, Bounds[1].x2); local boundsrandz = math.random(Bounds[2].z1, Bounds[2].z2); for i=1,limit do -- limit is a numbered variable cclone:MoveTo(Vector3.new(boundsrandx,y,boundsrandz)) cclone.Parent = script.Parent; print("X ", boundsrandx, " and Z", boundsrandz); print("Ore Spawned"); wait(.5) end
I know why, I had this problem with guns being put into one pack. Okay, so here is you problem, you have the object clones once, and then expect it to be cloned every time you call it. Instead of having
local cclone = copper:Clone()
at line six, have it in the loop, between line 16 and 17, so it becomes the new line 17, and it is cloned > >every time it iterates through. And fyi, this isn't C, C++ or C#, you don't have to have ";" at the end of > >every line. But good practice if you are learning any of those languages.
for i=1,limit do -- limit is a numbered variable local cclone = copper:Clone() --remove the cclone at line six, and this one clones every time it iterates. cclone:MoveTo(Vector3.new(boundsrandx,y,boundsrandz)) cclone.Parent = script.Parent; print("X ", boundsrandx, " and Z", boundsrandz); print("Ore Spawned"); wait(.5) end