I got this script from ROBLOX but the problem is it only generates parts and not tools. Is there a way to make a certain area on my game, rain tools, and not parts? Please help, thank you! <3
-- Variables for Roblox services
local ServerStorage = game:GetService("ServerStorage")
-- Variable for the drop zone
local dropZone = script.Parent
-- Table that will store info for each falling object
local fallingStuffTable = {}
-- ============================================
-- Falling Objects
local cube =
{
MODEL = ServerStorage["Cube"],
DAMAGE = 1,
NUMBER_PER_MINUTE = 20,
CLEANUP_DELAY_IN_SECONDS = 5
}
table.insert(fallingStuffTable, cube)
-- ============================================
-- Random number generator that will calculate drop chance and random drop position
local randomGenerator = Random.new()
-- Function to check if the given object should drop
local function checkIfShouldDrop(object, delta)
-- Setup is in number of drops per minute; need to convert minutes to ticks
local dropsPerSecond = object.NUMBER_PER_MINUTE / 60
local ticksPerSecond = 1 / delta
local dropsPerTick = dropsPerSecond / ticksPerSecond
-- Calculate random chance
local randomNumber = randomGenerator:NextNumber()
return randomNumber < dropsPerTick
end
-- Finds a random position inside of the given part and returns a randomly rotated CFrame at that position
local function getRandomCFrameInVolume(partVolume)
-- Calculate the position component of the random CFrame
local x = randomGenerator:NextInteger(-partVolume.Size.X/2, partVolume.Size.X/2)
local y = randomGenerator:NextInteger(-partVolume.Size.Y/2, partVolume.Size.Y/2)
local z = randomGenerator:NextInteger(-partVolume.Size.Z/2, partVolume.Size.Z/2)
local localOffset = Vector3.new(x, y, z)
local worldOffset = partVolume.CFrame:pointToWorldSpace(localOffset)
-- Calculate the rotation component of the random CFrame
local twoPi = math.pi * 2
local xRotation = randomGenerator:NextNumber() * twoPi
local yRotation = randomGenerator:NextNumber() * twoPi
local zRotation = randomGenerator:NextNumber() * twoPi
local CFrame = CFrame.Angles(xRotation, yRotation, zRotation)
-- Add the position and rotation together to get the full random CFrame
CFrame = CFrame + worldOffset
return CFrame
end
-- Sets the position of the falling object
-- This function checks if the object is a Part or a Model, as those are positioned differently
local function positionFallingObject(object)
local objectCFrame = getRandomCFrameInVolume(dropZone)
if object:IsA("BasePart") then
object.CFrame = objectCFrame
elseif object:IsA("Model") then
if not object.PrimaryPart then
object.PrimaryPart = object:FindFirstChildWhichIsA("BasePart", true)
end
object.PrimaryPart.CFrame = objectCFrame
end
object.Parent = game.Workspace
end
-- Connects the given collision function to the object's "Touched" event, but only if that object is a Part
-- Otherwise, it tries this function on all of the object's children
local function attachCollisionFunction(item, collisionFunction)
if item:IsA("BasePart") then
item.Touched:Connect(collisionFunction)
else
for _, child in ipairs(item:GetChildren()) do
attachCollisionFunction(child, collisionFunction)
end
end
end
-- Creates the collision function to attach to the object
local function setupFallingObjectCollisions(object, damage)
-- The collision function; must be declared in this scope as it needs reference to "object" and "damage" params
local function onTouch(otherObject)
local character = otherObject.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid:TakeDamage(damage)
object:Destroy()
end
end
-- Attach the above function to the falling object
attachCollisionFunction(object, onTouch)
end
-- Cleans up the falling object after a delay
local function objectCleanup(object, cleanupDelay)
delay(cleanupDelay, function()
if object then
object:Destroy()
end
end)
end
-- Update loop; on every loop, checks if an object should be made and, if so, creates that object
local last = tick()
while wait() do
local now = tick()
local delta = now - last
for _, object in ipairs(fallingStuffTable) do
if checkIfShouldDrop(object, delta) then
local obj = object.MODEL:Clone()
positionFallingObject(obj)
setupFallingObjectCollisions(obj, object.DAMAGE)
objectCleanup(obj, object.CLEANUP_DELAY_IN_SECONDS)
end
end
last = now
end

9 comments
ouch. what's so wrong bout trying to learn? THANK YOU! <3 ^_^
There's nothing wrong with trying to learn, but what you failed to do was the "try" aspect of that. You just went and got a free model and asked us how to fix it for you without attempting it on your own, that is where the problem lies.
There are actually people who have posted here, and they said they got it a from a free model, but what they did differently was telling us how they tried, it usually wasn't much and was completely wrong, but they did make that first step that you failed to do.
I dont start the part where I should set object = object.Handle. I mean where's the first line of the function? I'm really sorry for being dumb. :(
You aren't dumb, you just lack the knowledge. Line 66 is where you set it, and if you do want to actually learn scripting of your own, go to https://developer.roblox.com
thank you so much brother! <3
uhm, sorry bro but i just tested it and it actually didn't work. :(
sorry for the late response, did it show any errors when you ran it?
errors will show up in the "output" window