Hello, So I have this script which makes parts randomly fall from the sky however I’m trying to make it so that I can drag this script into any part and expand the part and it will generate the parts to a random position within the part the script it’s located in. If that makes any sense. So Heres the script I don’t know much about vector3.random or stuff like that so any suggestions would be much appreciated. Kind Regards ZoomCode!
while true do
wait(5)
for i = 1,500 do
local p = mesh:Clone()
wait(.2)
p.Position = Vector3.new(math.random(-245,225),95,math.random(-245,225))
p.Parent = script.Parent
end
end
Place a script within a part and it will detect the outer edges by using it’s size to compare from it’s center. You should be able to chuck the necessary variables inside of the math.random.
Hope this helped! Let me know if you need further assistance!
instead of doing that why do you have one large invisible part, then you have invisible parts in that large part from where the part can be generated, and you would make this into a model, and put all the invisible parts in a folder in the model or another model in the model, then you just do this:
local invisibleParts = -[[-put link to invisible parts here]]:GetChildren()
while true do
wait(5)
local clone = mesh:Clone()
local position = invisibleParts[math.random(1,#invisibleParts).Position
clone.Parent = script.Parent
clone.Position = position
end
local Spawner = script.Parent
while wait(5) do
for i = 1,500 do
local p = mesh:Clone()
local Hight = Spawner.CFrame.Y
local XSize = Spawner.Size.X/2
local ZSize = Spawner.Size.Z/2
p.CFrame = CFrame.new(math.random(-XSize,XSize),Hight,math.random(-ZSize,ZSize))
p.Parent = Spawner
wait(.2)
end
end
Thanks this almost works The only thing it’s missing is I need the parts to all fall under it they are falling a little off that way they fall right under it so basically where ever I move the part it’ll rain parts if that makes sense but it almost works Thank you!
local position = {
Pos1 = Vector3.new(1,1,1)
Pos2 = Vector3.new(2,2,2)
}
local function randomPos()
local random = math.random(2) -- More if you have more position
local newPos = position["Pos"..random] -- EX: position.Pos1 or position.Pos2
return newPos
end
This should work. The math.random() function for the X Position and the Z Position will choose a random number inside the bounds of the Spawner on that axis. Basically, it’s just getting the Spawner’s Position and adding or subtracting half of the size of the Spawner from its Position (the middle of the Spawner).
local Spawner = script.Parent
while true do
for i = 1, 500 do
local p = mesh:Clone()
local xPos = math.random(Spawner.Position.X - Spawner.Size.X/2, Spawner.Position.X + Spawner.Size.X/2)
local zPos = math.random(Spawner.Position.Z - Spawner.Size.Z/2, Spawner.Position.Z + Spawner.Size.Z/2)
p.Position = Vector3.new(xPos, Spawner.Position.Y, zPos)
p.Parent = Spawner
task.wait(0.2)
end
task.wait(5)
end