I am trying to make parts rain from the sky but somehow they don’t appear so can someone show me whats wrong with it?
this is the code:
local Debris = game:GetService(“Debris”)
local partCount = 100
while true do
end
local part = Instance.new("Part")
part.Parent = game.Workspace.Part
local randomX = math.random(-200, 200)
local randomZ = math.random(-200, 200)
part.Position = Vector3.new(randomX, 50, randomZ)
task.wait(1)
adding a end below your while script will end the loop, if you want it to continue and spawn the part, yes (only the one you put above local part = Instance.new("Part"))
Other Notes:
If you already placed a while loop in the script (hoisted) you can’t put another script unless you do
You are ending the while loop right after starting it.
You are parenting the part to another Part, I rather suggest to just parent it to workspace.
Next we can use Debris to delay the destruction of the parts. Also let’s only make 100 parts and then stop, for this we need to make a for loop.
local Debris = game:GetService("Debris")
local partCount = 100
-- i starts at 1, ends at partCount, each time +1 gets added
for i = 1, partCount, 1 do
local part = Instance.new("Part")
part.Position = Vector3.new(math.random(-200, 200), 50, math.random(-200, 200))
part.Parent = workspace
Debris:AddItem(part, 5) -- part will be destroyed after 5 seconds
task.wait(1) -- delay until the next rain drop
end
-- Anything below the for loop will wait until the for loop has concluded.
Inside of the while loop I would clone the RainTemplatePart (created in the 1st point)
Position it randomly using math.random() (just like you did)
Use DebrisService to add the item
It would look something like this:
local DebrisService = game:GetService("Debris")
local RainTemplate = Instance.new("Part") --you can make it inside of workspace and just do local RainTemplate = workspace.RainTemplate
RainTemplate.Size = Vector3.new(1,3,1)
RainTemplate.Transparency = 0.5
RainTemplate.Material = Enum.Material.Glass
local createdRain = 0
local MAX_RAIN = 100
local DELAY = 1
coroutine.wrap(function()--coroutine not needed, you can just use task.spawn()
while MAX_RAIN > createdRain do
createdRain += 1
local randomX = math.random(-200,200)
local randomZ = math.random(-200,200)
local rainDrop = RainTemplate:Clone()
rainDrop.Position = Vector3.new(randomX, 50, randomZ)
rainDrop.Parent = workspace --you can create a folder where you can store all the instances created
DebrisService:AddItem(rainDrop, 5)
task.wait(DELAY)
end
end)() --call it at the end