Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BLACKHOLE v4.3 LEGACY SCRIPT -- [This is an older version!]
- -- ↓ CUSTOMIZABLE SETTINGS ↓ --
- local hole = script.Parent.Parent
- local gravitationalConstant = 1000 -- Default value for the strength of the attraction [1000 is default for a black hole]
- local eventHorizonDistance = hole.Size.X/5 -- Prevents objects from getting too fast and disappearing after passing through singularity
- local proportionalGravity = true -- Toggle between proportional (true) and custom (false) gravitational pull
- local sizeIncreaseFactor = 0.01 -- Factor by which the blackhole's size increases after consuming an object
- local adjustEventHorizon = false -- Toggle if you want the event horizon to change as the blackhole gets bigger (false is default for realism)
- local isAbsorptionEnabled = true -- Toggle to enable or disable absorption (Object deletion)
- local killPlayers = true -- Toggle to enable or disable killing players when they touch the blackhole and also prevents them from being pulled (false)
- local weldRemovalZoneSize = hole.Size.X * 4 -- Size of the zone where welded objects/models collapse into particles
- local absorbedParts = {} -- Store absorbed parts
- function ApplyGravity(object)
- local direction = hole.Position - object.Position
- local distance = direction.Magnitude
- local forceMagnitude
- if proportionalGravity then
- forceMagnitude = (gravitationalConstant * hole.Size.X * object.Size.X) / (distance * distance)
- else
- forceMagnitude = gravitationalConstant -- Use custom gravitational constant
- end
- local force = direction.Unit * forceMagnitude
- object.Velocity = object.Velocity + force
- end
- local function CheckAndApplyGravity(obj)
- 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
- return
- end -- Add more classnames if targeted if not all objects are pulled
- if obj == hole then
- return -- Excludes the black hole itself from gravitational pull
- end
- if obj:IsA("Player") and not killPlayers then
- return -- Exclude players from being affected by the black hole if killing players is disabled
- end
- if obj.Anchored then
- return -- Prevents black hole from applying gravity to anchored objects
- end
- local distanceToHole = (hole.Position - obj.Position).Magnitude
- if distanceToHole < eventHorizonDistance then
- return -- Exclude objects within the event horizon from gravitational pull
- end
- ApplyGravity(obj)
- -- Check if the object is within the weld removal zone
- local distanceToWeldRemovalZone = (hole.Position - obj.Position).Magnitude
- if distanceToWeldRemovalZone < weldRemovalZoneSize then
- obj:BreakJoints() -- Break joints for objects within the weld removal zone
- end
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- for _, object in pairs(game.Workspace:GetDescendants()) do
- CheckAndApplyGravity(object)
- end
- end)
- function onTouch(part)
- local humanoid = part.Parent:FindFirstChild("Humanoid")
- if humanoid then
- humanoid.Health = 0
- end
- part.CanCollide = true -- Makes objects pass through each other for faster consumption (Still in Beta, changing it to false may cause glitches!)
- end
- function onTouched(part)
- if not isAbsorptionEnabled then
- return
- end
- if part.Anchored then
- return -- Excludes anchored objects from deletion
- end
- -- Check if the part has already been absorbed
- if absorbedParts[part] then
- return
- end
- absorbedParts[part] = true -- Mark the part as absorbed
- -- ABSORPTION CUSTOMIZATION (How object will be absorbed) --
- part.BrickColor = BrickColor.new(0) -- Color it changes into before getting deleted (White is default)
- part.Material = Enum.Material.Neon -- Material it changes into before getting deleted (Neon is default)
- part.Anchored = true -- Makes objects become unanchored (If in a group or folder) to be pulled in once it touches the event horizon
- part.CanCollide = false -- Make object pass through eachother
- local transparencySteps = {0.25, 0.5, 0.75} -- Transparency changes (Appearing to fade out of reality)
- for _, transparency in ipairs(transparencySteps) do
- part.Transparency = transparency
- wait(0.01) -- How long the fading will last (In seconds) on each transparency increment
- end
- part:Destroy() -- Delete the part after the fading effect
- -- Increase the blackhole's size after consuming an object
- hole.Size = hole.Size + Vector3.new(sizeIncreaseFactor, sizeIncreaseFactor, sizeIncreaseFactor)
- -- Adjust event horizon if toggled
- if adjustEventHorizon then
- eventHorizonDistance = hole.Size.X
- end
- end
- local connection = hole.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement