My blackhole script keeps cloning and disappearing after a few secconds when it shouldn`t be can somebody help?
--!strict
-- ░░ BLACK‑HOLE SERVER SCRIPT ░░
-- Works in ServerScriptService
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")
local lighting = game:GetService("Lighting")
local SoundService = game:GetService("SoundService")
local Sounds = SoundService:WaitForChild("Blackhole")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local rEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local CameraShakeEvent = rEvents:WaitForChild("CameraShakeEvent") or ReplicatedStorage:WaitForChild("CameraShakeEvent")
local textTemplate1 = " tipped "
local textTemplate2 = " robux."
local CollectionService = game:GetService("CollectionService") -- ADDED for playStageSound
if not CameraShakeEvent or not CameraShakeEvent:IsA("RemoteEvent") then
CameraShakeEvent=Instance.new("RemoteEvent")
CameraShakeEvent.Name="CameraShakeEvent"
CameraShakeEvent.Parent=rEvents or ReplicatedStorage
end
local stages = {
"Stage1",
"Stage2",
"Stage3"
}
local function growPart(part, targetSize, time)
local tweenInfo = TweenInfo.new(time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goals = { Size = targetSize }
if part:IsA("Decal") then return end
local tween = TweenService:Create(part, tweenInfo, goals)
tween:Play()
end
-- ADDED: Transparency tween helper
local function transparentPart(part, targetTransparency, time)
local tweenInfo = TweenInfo.new(time, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
if part:IsA("BasePart") then
TweenService:Create(part, tweenInfo, { Transparency = targetTransparency }):Play()
end
for _, child in ipairs(part:GetDescendants()) do
if child:IsA("Decal") or child:IsA("Texture") then
TweenService:Create(child, tweenInfo, { Transparency = targetTransparency }):Play()
elseif child:IsA("ParticleEmitter") or child:IsA("Trail") then
TweenService:Create(child, tweenInfo, { Transparency = NumberSequence.new(targetTransparency) }):Play()
elseif child:IsA("BasePart") then
TweenService:Create(child, tweenInfo, { Transparency = targetTransparency }):Play()
end
end
end
-- MODIFIED: clone and play sounds, no blocking tween.Completed:Wait()
local function playStageSound(model, player)
for _, obj in ipairs(Sounds:GetDescendants()) do
if obj:IsA("Sound") and CollectionService:HasTag(obj, "BlackholeSpecial") and CollectionService:HasTag(obj, model.Name) then
local soundClone = obj:Clone()
soundClone.Parent = model
soundClone:Play()
Debris:AddItem(soundClone, soundClone.TimeLength + 1)
if player then
CameraShakeEvent:FireClient(player, "ShakeOnce", 3, 1, 0.2, 1.5)
end
if model.Name == "Stage3" then
if player then
CameraShakeEvent:FireClient(player, "Shake", "Explosion")
CameraShakeEvent:FireClient(player, "ShakeOnce", 6, 2, 0.4, 3)
end
TweenService:Create(lighting, TweenInfo.new(3), {Brightness = 25}):Play()
else
TweenService:Create(lighting, TweenInfo.new(1), {Brightness = 10}):Play()
end
end
end
end
local function startBlackHoleEffect(player, amount)
if Sounds then Sounds.Start:Play() end
local blackholeFolder=ServerStorage:WaitForChild("BlackholeStages")
local previousStageClone=nil
TweenService:Create(lighting,TweenInfo.new(4.5),{ClockTime=4}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{ExposureCompensation=0.333}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{Ambient=Color3.fromRGB(128,0,255)}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{OutdoorAmbient=Color3.fromRGB(128,0,255)}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{ColorShift_Bottom=Color3.fromRGB(128,0,255)}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{ColorShift_Top=Color3.fromRGB(128,0,255)}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{EnvironmentDiffuseScale=0}):Play()
TweenService:Create(lighting,TweenInfo.new(4.5),{EnvironmentSpecularScale=0}):Play()
lighting.GeographicLatitude=50
lighting.GlobalShadows=false
TweenService:Create(workspace,TweenInfo.new(9),{Gravity=workspace.Gravity/15}):Play()
local char=workspace:FindFirstChild(player.Name)
if char then
local fs=char:FindFirstChild("FS")
if fs and fs:IsA("Script") then
fs.Enabled=true
end
end
local previousSizes={}
for _,stageName in ipairs(stages) do
local stage=blackholeFolder:FindFirstChild(stageName)
if stage then
local stageClone=stage:Clone()
stageClone.Parent=ReplicatedStorage.BlackholeFolder
playStageSound(stageClone, player)
for _,part in ipairs(stageClone:GetDescendants()) do
if part:IsA("BasePart") and (part.Name=="Center" or part.Name=="Lensing") then
local originalSize=part.Size
local previousSize=previousSizes[part.Name] or Vector3.new(0.1,0.1,0.1)
part.Size=previousSize
growPart(part, originalSize, 2)
previousSizes[part.Name]=originalSize
end
end
if previousStageClone and previousStageClone.Parent then
-- MODIFIED: Wait 15 seconds before destroying previous stage so it lasts longer
coroutine.wrap(function()
task.wait(15)
if previousStageClone and previousStageClone.Parent then
previousStageClone:Destroy()
end
end)()
end
previousStageClone=stageClone
if stageClone.Name=="Stage3" then
workspace.Music.Value:Play()
local vP=blackholeFolder:FindFirstChildOfClass("Part")
if vP then
vP=vP:Clone()
vP.Parent=workspace
Debris:AddItem(vP,60)
if amount~=false then
local aV=vP:FindFirstChild("MainAttach")
if aV then
local bG=aV:FindFirstChildOfClass("BillboardGui")
if bG then
local dT = bG:FindFirstChildOfClass("TextLabel")
if dT then
dT.Text = tostring(player.Name)..tostring(textTemplate1)..tostring(amount)..tostring(textTemplate2) or "Error"
end
end
end
end
end
if Sounds then
-- Clone and play disappear sounds so they are not cut off by destroying stageClone
local function playAndDebris(soundName)
local snd = Sounds:FindFirstChild(soundName)
if snd then
local sndClone = snd:Clone()
sndClone.Parent = workspace -- or SoundService
sndClone:Play()
Debris:AddItem(sndClone, sndClone.TimeLength + 1)
end
end
playAndDebris("EndSparkle1")
playAndDebris("EndSparkle2")
playAndDebris("EndSparkle3")
playAndDebris("End")
end
-- Start transparency fade after 2 seconds (sync with disappear sounds)
task.delay(2, function()
for _,part in ipairs(stageClone:GetDescendants()) do
transparentPart(part, 1, 2)
end
end)
-- Delay destruction to let sounds and transparency finish
task.delay(4, function()
if stageClone and stageClone.Parent then
TweenService:Create(lighting,TweenInfo.new(9),{Ambient=Color3.fromRGB(70,70,70)}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{OutdoorAmbient=Color3.fromRGB(70,70,70)}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{ColorShift_Bottom=Color3.fromRGB(0,0,0)}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{ColorShift_Top=Color3.fromRGB(0,0,0)}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{Brightness=1}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{ClockTime=14.5}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{ExposureCompensation=0}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{EnvironmentDiffuseScale=1}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{EnvironmentSpecularScale=1}):Play()
TweenService:Create(lighting,TweenInfo.new(9),{GeographicLatitude=50}):Play()
lighting.GlobalShadows=true
TweenService:Create(workspace,TweenInfo.new(9),{Gravity=workspace.Gravity*15}):Play()
stageClone:Destroy()
end
end)
if not char then return end
local humanoid=char:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
if humanoid.UseJumpPower then
TweenService:Create(humanoid,TweenInfo.new(9),{JumpPower=50}):Play()
else
TweenService:Create(humanoid,TweenInfo.new(9),{JumpHeight=7.2}):Play()
end
local fs=char:WaitForChild("FS",0.1)
if fs and fs:IsA("Script") then
local s=fs:WaitForChild("Stop",0.1)
if not s or not s:IsA("Script") then return end
s.Value=true
end
return
end
task.wait(2)
workspace.Music.Value:Stop()
end
end
end
Players.PlayerAdded:Connect(function(player)
local isCreator = player.UserId == game.CreatorId
local isHighRank = player:GetRankInGroup(game.CreatorId) > 254
if not (isCreator or isHighRank) then return end
-- Listen to chat command
player.Chatted:Connect(function(msg)
local prefix = require(script.Parent.Parent).Settings.Prefix or ""
if msg:lower() == prefix .. "blackhole" then
startBlackHoleEffect(player, false)
end
end)
local blackholeEvent = ReplicatedStorage:FindFirstChild("BlackholeEvent")
if not blackholeEvent then return end
-- Listen to RemoteEvent fired from client
blackholeEvent.OnServerEvent:Connect(function(_,player, amount)
if player then
startBlackHoleEffect(player, amount)
end
end)
end)