I was in the middle of making an AI for an NPC then stumbled upon some lag. Thankfully, I was able to resolve the explosions from lagging the entire server.
However, everytime a new Model Instance was made for the bombs, it still proceeded to lag. Here is a recorded GIF of the issue.
https://gyazo.com/c9b8cebc2f2ba99a12fe9a1ff6908715
So far, I have tried to research ways to resolve this issue and yet, there was none that I could find.
Here’s the provided Tool Script.
local Folder = game.ReplicatedStorage.Tools
local Tool = script.Parent
local Handle = Tool.Handle
local Model = Tool.Model
Tool.Activated:Connect(function()
local ToolClone = Folder.Bomb:Clone()
ToolClone.Parent = Tool.Parent
local New_Model = Instance.new("Model")
New_Model.Parent = workspace
New_Model.Name = "Pumpkin Bomb"
Handle.Parent = New_Model
Model.Parent = New_Model
Tool:Destroy()
Handle.Ticking_SFX:Play()
wait(4)
local Position = Handle.Position
Model:Destroy()
local MaximumDamage = 45
local MinimumDamage = 7
Handle.Ticking_SFX:Stop()
local Explosion = Instance.new("Explosion")
Explosion.ExplosionType = Enum.ExplosionType.CratersAndDebris
Explosion.DestroyJointRadiusPercent = 0
Explosion.BlastPressure = 0
Explosion.Position = Position
Explosion.BlastRadius = 15
Explosion.Parent = workspace
local Boom_SFX = Instance.new("Sound", Explosion)
Boom_SFX.SoundId = "rbxassetid://12222084"
Boom_SFX.Volume = 3
Boom_SFX.Name = "Boom_SFX"
Boom_SFX:Play()
Explosion.Hit:Connect(function(Hit, Distance)
local Debounce = false
if not Debounce then
if Hit.Parent:FindFirstChild("Humanoid") then
Debounce = true
Boom_SFX:Play()
local Humanoid = Hit.Parent.Humanoid
Humanoid:TakeDamage((1 - Distance / Explosion.BlastRadius) * (MaximumDamage - MinimumDamage) + MinimumDamage)
end
end
end)
Boom_SFX.Ended:Wait()
New_Model:Destroy()
end)