Hello Everyone,
I was making a bomb when I noticed that the bomb causes a lag spike.
I’m not sure why but here is the script:
local AlreadyHit = {}
local PlayerAlreadyHit = {}
local Explosion = Instance.new("Explosion")
Explosion.BlastPressure = 0
Explosion.BlastRadius = 100
Tool.Parent = workspace
Tool.Handle:FindFirstChild("TouchInterest"):Destroy()
task.wait(Tool:GetAttribute("DetonationTime"))
Explosion.Position = Tool.Handle.Position
Explosion.Parent = workspace
Explosion.Hit:Connect(function(part)
Explosion.Hit:Connect(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid then
local player = Players:GetPlayerFromCharacter(Humanoid.Parent)
if player and not table.find(PlayerAlreadyHit,player.Name) then
table.insert(PlayerAlreadyHit,player.Name)
Humanoid:TakeDamage(Tool:GetAttribute("Damage"))
elseif not table.find(PlayerAlreadyHit,part.Parent.Name) then
Humanoid:TakeDamage(Tool:GetAttribute("Damage"))
end
else
if not table.find(AlreadyHit,part.Name) and part.Name == "DamagePart" then
table.insert(AlreadyHit,part.Name)
part.Parent:SetAttribute("Health",part.Parent:GetAttribute("Health") - (Tool:GetAttribute("Damage") * 5))
end
end
end)
Tool.Handle.Transparency = 1
task.wait(1)
Tool:Destroy()