I want to do a pizza rain

  1. What do i want to achieve? I want to do a pizza rain in a specific zone

I did this script, no errors in the output, and it’s not working, and then i want that if the pizza touch a player then the position of the player change (i guess that i have to fireallclients for it)


this is the originpart (when there is the rain)

local rainOrigin = script.Parent

local x = rainOrigin.Size.X / 2
local z = rainOrigin.Size.Z / 2


while true do
		local rain = game.ReplicatedStorage.Pizza.MeshPart:Clone()
		local rx = math.random(-x , x)
		local rz = math.random(-z , z)

	rain.CFrame = rainOrigin.CFrame * CFrame.new(rx, 0, rz)


		wait(0.5)
	end

it is a normal script under the pizza origin

Parent the rain to workspace.

local rainOrigin = script.Parent

local x = rainOrigin.Size.X / 2
local z = rainOrigin.Size.Z / 2


while true do
		local rain = game.ReplicatedStorage.Pizza.MeshPart:Clone()
		local rx = math.random(-x , x)
		local rz = math.random(-z , z)

	rain.CFrame = rainOrigin.CFrame * CFrame.new(rx, 0, rz)
+rain.Parent = workspace

		wait(0.5)
	end
1 Like

Ty for the answer, uh i totally forgot it, i do it rn

TYSM it is working… but how can i destroy the rain? Because if i write wait(5) and the Rain:Destroy() then the loop wait 5 to drop the pizzas

local rainOrigin = script.Parent

local x = rainOrigin.Size.X / 2
local z = rainOrigin.Size.Z / 2


while true do
	local rain = game.ReplicatedStorage.Pizza.MeshPart:Clone()
	local rx = math.random(-x , x)
	local rz = math.random(-z , z)

	rain.CFrame = rainOrigin.CFrame * CFrame.new(rx, 0, rz)
	rain.Parent = workspace
	
	spawn(function()
		task.wait(5)
		rain:Destroy()
	end)

	wait(0.5)
end
1 Like

You can use Couretine (idk how to spell it lol) or spawn()

I personally use spawn just cause it is easier.

Add this before the wait thing:

spawn(function()
   wait(5)
   rain:Destroy()
end
1 Like

Tysm for the answer i try it rn

edit: it is working tysm

ty for the answer too it is working i just have to do that if player touch the rain then fireallclients

Ok guys it works tysm everyone for helping! :smiley:

You can also use: local Debris = game:GetService(“Debris”); Debris:AddItem(item, delay); to get rid of it after 5 seconds.

1 Like

Ty for the answer… Yes i could do your solution too

--serverscript
If you are interested these are my scripts

--localscript