Code:
function Service.LuckyBlockEffect(self: Service, Id: string)
if not self.Drops[Id] or not self.Drops[Id].DropModel then warn("SOMETHING WENT WRONG DISPLAYING THE LUCKYBLOCK EFFECT: ", self.Drops[Id]) return end
local Data = self.Drops[Id]
self.Drops[Id] = nil
local Origin: CFrame = Data.DropModel:GetPivot()
local Root: Part = Data.DropModel.PrimaryPart
local BrainrotName: string = Data.Value
if not Root or not BrainrotName or not ReplicatedStorage.Assets.Brainrots:FindFirstChild(BrainrotName) then
Data.DropModel:Destroy()
return
end
local LookAt = Origin.Position
local Character = Player.Character
local HumanoidRootPart = Character and Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then LookAt = HumanoidRootPart.Position end
--Helper
local function ScaleEffect(Model: Model, TargetScale: number, Duration: number, isFadeOut: boolean?)
local CurrentScale = Model:GetScale()
local StartScale = isFadeOut and CurrentScale or 0.05 -- avoid 0, some parts/joints don't like true zero scale
-- If a VfxInstance exists, scale into its center instead of the
-- model's pivot. Captured before the initial ScaleTo so this is
-- the VfxInstance's true resting position, not its shrunk one.
local VfxInstance = Model:FindFirstChild("VfxInstance") :: BasePart?
local Origin, AnchorPosition, LocalOffset
if VfxInstance then
Origin = Model:GetPivot()
AnchorPosition = VfxInstance.Position
LocalOffset = Origin:PointToObjectSpace(AnchorPosition) / CurrentScale
end
local function ApplyScale(Scale: number)
Model:ScaleTo(Scale)
if VfxInstance then
local NewPosition = AnchorPosition - Origin:VectorToWorldSpace(LocalOffset * Scale)
Model:PivotTo(CFrame.new(NewPosition) * Origin.Rotation)
end
end
ApplyScale(StartScale)
local ScaleValue = Instance.new("NumberValue")
ScaleValue.Value = StartScale
local Connection
Connection = ScaleValue.Changed:Connect(ApplyScale)
local Tween = TweenService:Create(ScaleValue, TweenInfo.new(Duration, Enum.EasingStyle.Back, Enum.EasingDirection.Out), { Value = TargetScale })
Tween:Play()
for _, v in Model:GetDescendants() do
if v:IsA("BasePart") or v:IsA("Decal") or v:IsA("Texture") then
TweenService:Create(v, TweenInfo.new(1,Enum.EasingStyle.Quart,Enum.EasingDirection.Out,0,false,0.1), { Transparency = 1 }):Play()
end
end
task.wait(Duration) -- yields until the tween finishes, no Completed connection needed
Connection:Disconnect()
ScaleValue:Destroy()
end
local function PlayDetachedSound(SourceSound: Sound, Parent: Instance)
local Sound = SourceSound:Clone()
Sound.Parent = Parent
Sound:Play()
if Sound.IsLoaded then
Debris:AddItem(Sound, Sound.TimeLength + 0.1)
else
local Conn
Conn = Sound.Loaded:Connect(function()
Conn:Disconnect()
Debris:AddItem(Sound, Sound.TimeLength + 0.1)
end)
Debris:AddItem(Sound, 3)
end
end
--
--LuckyBLock
local function LuckyBlock()
local vfx = Data.DropModel:FindFirstChild("BrainrotSpin")
if vfx then
shared.vfx.emit(vfx)
end
TweenService:Create(Root, TweenInfo.new(0.25), { CFrame = Root.CFrame * CFrame.new(0, 1, 0) }):Play()
task.wait(0.25)
LuckyBlocksEntries[HttpService:GenerateGUID()] = {
Part = Root,
Start = os.clock(),
Original = Root.CFrame
}
task.wait(ShakeDuration)
ScaleEffect(Data.DropModel,1.2,0.25)
end
LuckyBlock()
Debris:AddItem(Data.DropModel,2)
--
--Brainrot intermission
local PooledObjects = {} :: {Model}
local randomNum = math.random(6,8)
for i = 1,randomNum do
local BrainrotObject = getPooledObject("Brainrots")
--Create new brainrot if every objecy is busy
if not BrainrotObject then
--All busy
local randomBrainrot = BrainrotDrops:GetChildren()[math.random(1,#BrainrotDrops:GetChildren())]
if randomBrainrot then randomBrainrot = randomBrainrot:Clone()
ObjectPool.Brainrot[randomBrainrot] = false
randomBrainrot.Parent = workspace.Ignore.BrainrotDrops
BrainrotObject = randomBrainrot
end
end
--
if BrainrotObject then
ObjectPool.Brainrot[BrainrotObject] = true -- Mark as busy
BrainrotObject.Parent = workspace.Ignore.BrainrotDrops
table.insert(PooledObjects,BrainrotObject)
for _,v in pairs(BrainrotObject:GetDescendants()) do
if v:IsA("TextLabel") then
v.TextTransparency = 0
end
if v:IsA("UIStroke") then
v.Transparency = 0
end
if v:IsA("BasePart") then
v.LocalTransparencyModifier = 0
end
end
BrainrotObject:PivotTo(CFrame.lookAt(Origin.Position,Vector3.new(LookAt.X,Origin.Position.Y,LookAt.Z)))
task.wait()
PlayDetachedSound(ReplicatedStorage.Assets.SFX.ClickSFX, BrainrotObject)
task.wait(0.1)
for _,v in pairs(BrainrotObject:GetDescendants()) do
if v:IsA("TextLabel") then
v.TextTransparency = 1
end
if v:IsA("UIStroke") then
v.Transparency = 1
end
if v:IsA("BasePart") then
v.LocalTransparencyModifier = 1
end
end
end
end
for _,Object in PooledObjects do
ObjectPool.Brainrot[Object] = false -- Mark as not busy
end
--
--Display brainrot
local Brainrot: Model = ReplicatedStorage.Assets.Brainrots:FindFirstChild(BrainrotName)
if Brainrot then
local BrainrotClone = Brainrot:Clone()
BrainrotClone.Parent = workspace.Ignore.BrainrotDrops
local Overhead = ReplicatedStorage.Assets.BrainrotOverhead_Drop:Clone()
Overhead.Parent = BrainrotClone
Overhead.BrainrotName.Text = BrainrotName
--Size and position based off VfxInstance in BrainrotClone
local VfxInstance = BrainrotClone:FindFirstChild("VfxInstance") :: Part?
if VfxInstance then
Overhead.Adornee = VfxInstance
local VfxSize = VfxInstance.Size
local maxDimension = math.max(VfxSize.X, VfxSize.Y, VfxSize.Z)
-- Position: since VfxInstance's CFrame is the model's center, go up
-- to the top of it (half height) plus some padding to clear the head
local padding = 2
Overhead.StudsOffset = Vector3.new(0, VfxSize.Y*1.2 + padding, 0)
-- Scale: grow/shrink the billboard itself relative to model size
local baseSize = Overhead.Size -- e.g. UDim2.new(4, 0, 1, 0) from the template
local scaleFactor = math.clamp(maxDimension / 4, 0.5, 3) -- tune divisor/clamp to taste
Overhead.Size = UDim2.new(
baseSize.X.Scale * scaleFactor, baseSize.X.Offset,
baseSize.Y.Scale * scaleFactor, baseSize.Y.Offset
)
end
local Primary = BrainrotClone.PrimaryPart
if Primary then
BrainrotClone:ScaleTo(BrainrotClone:GetScale()/2)
BrainrotClone:PivotTo(CFrame.lookAt(Origin.Position, Vector3.new(LookAt.X, Origin.Position.Y, LookAt.Z)))
--Clear all VFX
for _,v in pairs(BrainrotClone:GetDescendants()) do
if v:IsA("ParticleEmitter") or v:IsA("Beam") or v:IsA("Trail") then
v:Destroy()
end
end
--Clear Brainrot
task.wait(0.4)
Debris:AddItem(BrainrotClone,0.05)
ScaleEffect(BrainrotClone,0.3,0.05,true)
--
end
end
--
end
Problem:
This is causing really high CPU usage in my game.
Video of problem:


