Advertisement
1m1m0

Blackhole v4.421 (W Model Support)

Jan 1st, 2024 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.34 KB | Source Code | 0 0
  1. -- MAIN BLACKHOLE v4.421 SCRIPT (With Model Attraction Support) --
  2.  
  3. local hole = script.Parent       -- More Information in [- CONTEXT -]
  4. local gravitationalConstantValue = hole.Configurations:FindFirstChild("GravitationalConstant")
  5. local eventHorizonDistanceValue  = hole.Configurations:FindFirstChild("EventHorizonDistance")
  6. local proportionalGravityValue   = hole.Configurations:FindFirstChild("ProportionalGravity")
  7. local sizeIncreaseFactorValue    = hole.Configurations:FindFirstChild("SizeIncreaseFactor")
  8. local adjustEventHorizonValue    = hole.Configurations:FindFirstChild("AdjustEventHorizon")
  9. local isAbsorptionEnabledValue   = hole.Configurations:FindFirstChild("IsAbsorptionEnabled")
  10. local killPlayersValue           = hole.Configurations:FindFirstChild("KillPlayers")
  11. local weldRemovalZoneSizeValue   = hole.Configurations:FindFirstChild("WeldRemovalZoneSize")
  12. local transparencyStepsValue     = hole.Configurations:FindFirstChild("TransparencySteps")
  13. local waitIntervalValue          = hole.Configurations:FindFirstChild("WaitInterval")
  14. local materialValue              = hole.Configurations:FindFirstChild("MaterialValue")
  15.  
  16. local absorbedParts = {} -- Store absorbed parts
  17.  
  18. local function ApplyGravity(object)
  19.     local direction = hole.Position - object.Position
  20.     local distance = direction.Magnitude
  21.     local forceMagnitude
  22.  
  23.     local gravitationalConstant = gravitationalConstantValue and gravitationalConstantValue.Value or 1000
  24.  
  25.     if proportionalGravityValue and proportionalGravityValue.Value then
  26.         forceMagnitude = (gravitationalConstant * hole.Size.X * object.Size.X) / (distance * distance)
  27.     else
  28.         forceMagnitude = gravitationalConstant -- Use custom gravitational constant
  29.     end
  30.  
  31.     local force = direction.Unit * forceMagnitude
  32.  
  33.     -- Apply force using BodyForce instead of setting velocity directly
  34.     local bodyForce = object:FindFirstChildOfClass("BodyForce") or Instance.new("BodyForce")
  35.     bodyForce.Force = force
  36.     bodyForce.Name = "BlackHoleForce"
  37.  
  38.     -- Attach BodyForce to object
  39.     bodyForce.Parent = object
  40. end
  41.  
  42. local function CheckAndApplyGravity(obj)
  43.     if not obj:IsA("BasePart") or obj:IsA("Model") or obj:IsA("Union") or obj:IsA("Tool") or obj:IsA("MeshPart") or obj:IsA("Mesh") then
  44.         return
  45.     end -- Add more classnames if targeted if not all objects are pulled
  46.  
  47.     if obj == hole then
  48.         return -- Excludes the black hole itself from gravitational pull
  49.     end
  50.  
  51.     if obj:IsA("Player") and (killPlayersValue and killPlayersValue.Value) then
  52.         return -- Exclude players from being affected by the black hole if killing players is enabled
  53.     end
  54.  
  55.     if obj.Anchored then
  56.         return -- Prevents black hole from applying gravity to anchored objects
  57.     end
  58.  
  59.     local distanceToHole = (hole.Position - obj.Position).Magnitude
  60.     local eventHorizonDistance = eventHorizonDistanceValue and eventHorizonDistanceValue.Value or hole.Size.X / 5
  61.  
  62.     if distanceToHole < eventHorizonDistance then
  63.         return -- Exclude objects within the event horizon from gravitational pull
  64.     end
  65.  
  66.     ApplyGravity(obj)
  67.  
  68.     -- Check if the object is within the weld removal zone
  69.     local weldRemovalZoneSize = weldRemovalZoneSizeValue and weldRemovalZoneSizeValue.Value or hole.Size.X * 4
  70.     if distanceToHole < weldRemovalZoneSize then
  71.         obj:BreakJoints() -- Break joints for objects within the weld removal zone
  72.     end
  73. end
  74.  
  75. local function onTouched(part)
  76.     local isAbsorptionEnabled = isAbsorptionEnabledValue and isAbsorptionEnabledValue.Value or false
  77.  
  78.     if not isAbsorptionEnabled then
  79.         return
  80.     end
  81.  
  82.     if part.Anchored then
  83.         return -- Excludes anchored objects from deletion
  84.     end
  85.  
  86.     -- Check if the part has already been absorbed
  87.     if absorbedParts[part] then
  88.         return
  89.     end
  90.  
  91.     absorbedParts[part] = true -- Mark the part as absorbed
  92.  
  93.     local colorValue = hole.Configurations:FindFirstChild("ColorValue")
  94.     local brickColor = colorValue and colorValue.Value or BrickColor.new(0)
  95.  
  96.     part.brickColor = brickColor -- Color it changes into before getting deleted
  97.  
  98.     local material = materialValue and materialValue.Value or Enum.Material.Neon
  99.     part.Material = material -- Material it changes into before getting deleted
  100.  
  101.     part.Anchored = true
  102.     part.CanCollide = false
  103.  
  104.     local transparencySteps = transparencyStepsValue and transparencyStepsValue.Value or "0.25,0.5,0.75"
  105.     local steps = {}
  106.     for step in transparencySteps:gmatch("([^,]+)") do
  107.         table.insert(steps, tonumber(step))
  108.     end
  109.  
  110.     local waitInterval = waitIntervalValue and waitIntervalValue.Value or 0.01
  111.  
  112.     for _, transparency in ipairs(steps) do
  113.         part.Transparency = transparency
  114.         wait(waitInterval) -- How long the fading will last (In seconds) on each transparency increment
  115.     end
  116.  
  117.     part:Destroy() -- Delete the part after the fading effect
  118.  
  119.     -- Increase the blackhole's size after consuming an object
  120.     local sizeIncreaseFactor = sizeIncreaseFactorValue and sizeIncreaseFactorValue.Value or 0.01
  121.     hole.Size = hole.Size + Vector3.new(sizeIncreaseFactor, sizeIncreaseFactor, sizeIncreaseFactor)
  122.  
  123.     -- Adjust event horizon if toggled
  124.     local adjustEventHorizon = adjustEventHorizonValue and adjustEventHorizonValue.Value or false
  125.  
  126.     if adjustEventHorizon then
  127.         eventHorizonDistanceValue.Value = hole.Size.X
  128.     end
  129. end
  130.  
  131. local connection = hole.Touched:Connect(onTouched)
  132.  
  133. game:GetService("RunService").Heartbeat:Connect(function()
  134.     for _, object in pairs(game.Workspace:GetDescendants()) do
  135.         CheckAndApplyGravity(object)
  136.     end
  137. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement