hello, i want to make a tool that makes blocks rain from the sky when clicked, i have the tool models and everything ready, I just need a bit of help. I would appreciate if anyone could help me with a script and i can add on to it if i want to change anything. Apologies if i am asking for too much
local Tool = script.Parent
local function Rain()
wait(.001) --Time before it starts raining
local part = Instance.new("Part")
part.Name = "Block"
part.Parent = workspace
part.Position = Vector3.new(math.random(script.Parent.Handle.Position.X - script.Parent.Handle.Size.X/2,script.Parent.Handle.Position.X + script.Parent.Handle.Size.X/2),(script.Parent.Handle.Position.Y + 80),math.random(script.Parent.Handle.Position.Z - script.Parent.Handle.Size.Z/2,script.Parent.Handle.Position.Z + script.Parent.Handle.Size.Z/2)) --or anywhere you want by just changing the selected part- The tool's handle, or mentioning the excact position you want to put it such as Vector3.new(1,1,1)!--
part.Anchored = false
part.Shape = "Block"
part.Material = "SmoothPlastic" --Or any material you want
part.Size = Vector3.new(1, 1, 1) --Or any size you want
part.Parent = workspace
wait(0.01) --Cooldown until next block
end
Tool.Activated:Connect(function()
Rain()
Rain()
Rain()
Rain()
Rain()
--The more times you input Rain(), the more blocks that will spawn!
end)
Make sure it’s a server script!
Edit: Rain() only spawns one block, but you can clone lines 3-13 and paste them to spawn more blocks and make sure you change the name of each part instanced!
Something like this would be much cleaner, but you got the right idea.
local debounce = false
local Tool = script.Parent
local function Rain(amount)
debounce = true
for i = 1, amount do
local part = Instance.new("Part")
part.Name = "Block"
part.Parent = workspace
part.Position = Vector3.new(math.random(script.Parent.Handle.Position.X - script.Parent.Handle.Size.X/2,script.Parent.Handle.Position.X + script.Parent.Handle.Size.X/2),(script.Parent.Handle.Position.Y + 80),math.random(script.Parent.Handle.Position.Z - script.Parent.Handle.Size.Z/2,script.Parent.Handle.Position.Z + script.Parent.Handle.Size.Z/2)) --or anywhere you want by just changing the selected part- The tool's handle, or mentioning the excact position you want to put it such as Vector3.new(1,1,1)!--
part.Anchored = false
part.Shape = "Block"
part.Material = "SmoothPlastic" --Or any material you want
part.Size = Vector3.new(1, 1, 1) --Or any size you want
part.Parent = workspace
end
wait(3) -- change this for faster/slower debounce times
debounce = false
end
Tool.Activated:Connect(function()
if not debounce then
Rain(5) -- rains 5 parts
end
end)
Both solutions are client sided, which means only the person who used the tool would see it.
Add a RemoteEvent called RainBlocks in ReplicatedStorage.
Add this in the tool:
local CanBeUsed = true
local WaitTime = 3
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Activated:Connect(function()
if CanBeUsed then
CanBeUsed = false
ReplicatedStorage.RainBlocks:FireServer()
wait(WaitTime)
CanBeUsed = true
end
end)
And add this in ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RandomService = Random.new()
local TimesToRainParts = 10 -- This is how many times parts will rain from the sky.
ReplicatedStorage.RainBlocks.OnServerEvent:Connect(function()
for Times = 1, TimesToRainParts do
local RandomPosition = Vector3.new(RandomService:NextInteger(1, 100), RandomService:NextInteger(1, 100), RandomService:NextInteger(1, 100)) -- Mess around with these to get your result.
local Part = Instance.new("Part")
-- Customize the part, color, anchored, surface, etc... right here
Part.Position = RandomPosition
Part.Parent = workspace
end
end)