Advertisement
1m1m0

Blackhole 4.0 Lite

Jan 1st, 2024 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | Source Code | 0 0
  1. -- [ Blackhole 4.0 Source Code Basics ] --
  2. -- Does not contain special functions as v4.3+, but does contain some aspects of v5.0+
  3. -- For archived versions of v4.3+, visit my pastebin: https://pastebin.com/u/1m1m0
  4.  
  5. local hole = script.Parent
  6. local gravitationalConstant = 1000 -- Adjust this value to control the strength of the attraction [1000 is default for a black hole]
  7. -- gravitational constants of half or a third of 1000 is perfect for gentle simulations.
  8. local velocityBasedGravity = true -- Toggle for velocity-base gravity (good for large scale simulations)
  9. local forceBasedGravity = false -- Toggle for bodyforce-base gravity (good for small scale simulations, LIMITED RANGE)
  10. local absorption = true -- Toggle to absorb objects or not
  11.  
  12. -- How the blackhole will pull objects (Uses VELOCITY, unlimited range, unstable simulations)
  13. if velocityBasedGravity then
  14.     function ApplyGravity(object)
  15.         local direction = hole.Position - object.Position
  16.         local distance = direction.Magnitude
  17.         local forceMagnitude = (gravitationalConstant * hole.Size.X * object.Size.X) / (distance * distance)
  18.         local force = direction.Unit * forceMagnitude
  19.  
  20.         object.Velocity = object.Velocity + force
  21.     end
  22. elseif forceBasedGravity then
  23.     -- Alternative gravitational pull. (Uses BODYFORCE, limited range, stable simulations)
  24.     local function ApplyGravity(object)
  25.         local direction = hole.Position - object.Position
  26.         local force = direction.Unit * gravitationalConstant
  27.  
  28.         local bodyForce = object:FindFirstChild("BlackHoleBodyForce")
  29.         if not bodyForce then
  30.             bodyForce = Instance.new("BodyForce")
  31.             bodyForce.Name = "BlackHoleBodyForce"
  32.             bodyForce.Force = force
  33.             bodyForce.Parent = object
  34.         else
  35.             bodyForce.Force = force
  36.         end
  37.     end
  38. end
  39.  
  40. local function CheckAndApplyGravity(obj)
  41.     if not obj:IsDescendantOf(game.Workspace) or not obj:IsA("BasePart") then -- This should include everything
  42.         return
  43.     end
  44. --  [Objects only]
  45.     if obj == hole or obj == obj:IsA("Player") then
  46.         return -- Excludes the players and black hole itself from gravitational pull, feel free to add more.
  47.     end
  48. --  [Unanchored objects only]
  49.     if obj.Anchored then
  50.         return -- Prevents black hole from applying gravity to the anchored objects. (Saves resources and compuation power)
  51.     end
  52.  
  53.     ApplyGravity(obj)
  54. end
  55.  
  56. game:GetService("RunService").Heartbeat:Connect(function()
  57.     for _, object in pairs(game.Workspace:GetDescendants()) do
  58.         CheckAndApplyGravity(object)
  59.     end
  60. end)
  61.  
  62. -- DAMAGE/KILLER (Kills players when they touch it) --
  63.  
  64. function onTouch(part)
  65.     local humanoid = part.Parent:FindFirstChild("Humanoid")
  66.     if humanoid then
  67.         humanoid.Health = 0
  68.     end
  69. end
  70.  
  71. -- DEMATERIALIZER (Deletes ANY object that touches it) --
  72.  
  73. hole.Touched:Connect(onTouch)
  74.  
  75. if absorption then
  76.     function onTouched(part)
  77.         if part.Anchored then -- Exclude anchored objects
  78.             return
  79.         end
  80.  
  81.         part.BrickColor = BrickColor.new(0) -- Color it changes into before getting deleted. (White is default)
  82.         part.Material = Enum.Material.Neon  -- Material it changes into before getting deleted. (Neon is default)
  83.         --[[ Additional absorption styles:
  84.         part.Anchored = true
  85.         part.CanCollide = false
  86.         --]]
  87.  
  88.         local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes. (Appearing to fade out of reality)
  89.         for _, transparency in ipairs(transparencySteps) do
  90.             part.Transparency = transparency
  91.             wait(0.01) -- How long (seconds) the fading will last (In seconds) on each transparency increment.
  92.         end
  93.  
  94.         part:Destroy() -- Delete part after completing trancparencySteps.
  95.     end
  96.  
  97.     local connection = hole.Touched:Connect(onTouched)
  98. end
  99.  
  100. -- (Do not credit me for this masterpiece of a script, all credit goes to ChatGPT who made this masterpiece into reality!) --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement