Advertisement
1m1m0

Blackhole v4.3 Legacy

Jan 1st, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.60 KB | Source Code | 0 0
  1. -- BLACKHOLE v4.3 LEGACY SCRIPT -- [This is an older version!]
  2.  
  3. -- ↓ CUSTOMIZABLE SETTINGS ↓ --
  4. local hole = script.Parent.Parent
  5. local gravitationalConstant = 1000 -- Default value for the strength of the attraction [1000 is default for a black hole]
  6. local eventHorizonDistance = hole.Size.X/5 -- Prevents objects from getting too fast and disappearing after passing through singularity
  7. local proportionalGravity = true -- Toggle between proportional (true) and custom (false) gravitational pull
  8. local sizeIncreaseFactor = 0.01 -- Factor by which the blackhole's size increases after consuming an object
  9. local adjustEventHorizon = false -- Toggle if you want the event horizon to change as the blackhole gets bigger (false is default for realism)
  10. local isAbsorptionEnabled = true -- Toggle to enable or disable absorption (Object deletion)
  11. local killPlayers = true -- Toggle to enable or disable killing players when they touch the blackhole and also prevents them from being pulled (false)
  12.  
  13. local weldRemovalZoneSize = hole.Size.X * 4 -- Size of the zone where welded objects/models collapse into particles
  14. local absorbedParts = {} -- Store absorbed parts
  15.  
  16. function ApplyGravity(object)
  17.     local direction = hole.Position - object.Position
  18.     local distance = direction.Magnitude
  19.     local forceMagnitude
  20.  
  21.     if proportionalGravity then
  22.         forceMagnitude = (gravitationalConstant * hole.Size.X * object.Size.X) / (distance * distance)
  23.     else
  24.         forceMagnitude = gravitationalConstant -- Use custom gravitational constant
  25.     end
  26.  
  27.     local force = direction.Unit * forceMagnitude
  28.  
  29.     object.Velocity = object.Velocity + force
  30. end
  31.  
  32. local function CheckAndApplyGravity(obj)
  33.     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
  34.         return
  35.     end -- Add more classnames if targeted if not all objects are pulled
  36.  
  37.     if obj == hole then
  38.         return -- Excludes the black hole itself from gravitational pull
  39.     end
  40.  
  41.     if obj:IsA("Player") and not killPlayers then
  42.         return -- Exclude players from being affected by the black hole if killing players is disabled
  43.     end
  44.  
  45.     if obj.Anchored then
  46.         return -- Prevents black hole from applying gravity to anchored objects
  47.     end
  48.  
  49.     local distanceToHole = (hole.Position - obj.Position).Magnitude
  50.     if distanceToHole < eventHorizonDistance then
  51.         return -- Exclude objects within the event horizon from gravitational pull
  52.     end
  53.  
  54.     ApplyGravity(obj)
  55.  
  56.     -- Check if the object is within the weld removal zone
  57.     local distanceToWeldRemovalZone = (hole.Position - obj.Position).Magnitude
  58.     if distanceToWeldRemovalZone < weldRemovalZoneSize then
  59.         obj:BreakJoints() -- Break joints for objects within the weld removal zone
  60.     end
  61. end
  62.  
  63. game:GetService("RunService").Heartbeat:Connect(function()
  64.     for _, object in pairs(game.Workspace:GetDescendants()) do
  65.         CheckAndApplyGravity(object)
  66.     end
  67. end)
  68.  
  69. function onTouch(part)
  70.     local humanoid = part.Parent:FindFirstChild("Humanoid")
  71.     if humanoid then
  72.         humanoid.Health = 0
  73.     end
  74.  
  75.     part.CanCollide = true -- Makes objects pass through each other for faster consumption (Still in Beta, changing it to false may cause glitches!)
  76. end
  77.  
  78. function onTouched(part)
  79.     if not isAbsorptionEnabled then
  80.         return
  81.     end
  82.  
  83.     if part.Anchored then
  84.         return -- Excludes anchored objects from deletion
  85.     end
  86.  
  87.     -- Check if the part has already been absorbed
  88.     if absorbedParts[part] then
  89.         return
  90.     end
  91.  
  92.     absorbedParts[part] = true -- Mark the part as absorbed
  93.    
  94.     -- ABSORPTION CUSTOMIZATION (How object will be absorbed) --
  95.    
  96.     part.BrickColor = BrickColor.new(0) -- Color it changes into before getting deleted (White is default)
  97.     part.Material = Enum.Material.Neon  -- Material it changes into before getting deleted (Neon is default)
  98.     part.Anchored = true                -- Makes objects become unanchored (If in a group or folder) to be pulled in once it touches the event horizon
  99.     part.CanCollide = false             -- Make object pass through eachother
  100.  
  101.     local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes (Appearing to fade out of reality)
  102.     for _, transparency in ipairs(transparencySteps) do
  103.         part.Transparency = transparency
  104.         wait(0.01) -- How long the fading will last (In seconds) on each transparency increment
  105.     end
  106.  
  107.     part:Destroy() -- Delete the part after the fading effect
  108.  
  109.     -- Increase the blackhole's size after consuming an object
  110.     hole.Size = hole.Size + Vector3.new(sizeIncreaseFactor, sizeIncreaseFactor, sizeIncreaseFactor)
  111.  
  112.     -- Adjust event horizon if toggled
  113.     if adjustEventHorizon then
  114.         eventHorizonDistance = hole.Size.X
  115.     end
  116. end
  117.  
  118. local connection = hole.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement