-- 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
