How to decrease lag from explosions (I'm living off gaming with a potato)

But this is the best I can do, make a fading-remove function affected parts by the blast range and using a for loop

so this is the code i excevuted:

function OnTouch(boomer)
local e = Instance.new("Explosion")
    e.Hit:Connect(function(part) -- this is the Explosion.hit event to fade-remove the parts
          for p = 0,1,.1 do
      part.Transparency = p
      wait(.3) 
      if part.Transparency == 1 then
      part:Destroy()
      end
      end
      end) -- i think u understand wat im doing right here
	e.BlastPressure = 800000
	e.BlastRadius = 70 -- note these values are intended for nuke effect
	e.Parent = workspace
    e.Position = script.Parent.Position
    script.Parent:Destroy()
	end
script.Parent.Touched:Connect(OnTouch)

Problem is the affect parts are not deleted from the .hit function, any help?

1 Like

I know nothing about scripting but maybe you should just make it where its not where it explodes things and it just damages player? I dont know where im trying to go with this

1 Like

No i mean i want to delete the parts that r affected by the explosion blast range by doing a fade effect and then delete it and if I can get this over with then the lag will reduce significantly and no, I want it to explode inside a building and kill players

1 Like

Try this

function OnTouch(boomer)
local e = Instance.new("Explosion")
    e.Hit:Connect(function(part) -- this is the Explosion.hit event to fade-remove the parts
          for p = 0,1,.1 do
      part.Transparency = p
      wait(.3) 
      if part.Transparency == 1 then
      part:Destroy()
      end
      end
      end) -- i think u understand wat im doing right here
	e.BlastPressure = 800000
	e.BlastRadius = 70 -- note these values are intended for nuke effect
	e.Parent = workspace
    e.Position = script.Parent.Position
    script.Parent:Destroy()
	end
script.Parent.Touched:Connect(OnTouch)
1 Like

is this just the same thing i just wrote?

1 Like

I just changed the if part.Transparency ==0 then part(Which will destroy the part if its transparency is 0)to if part.Transparency ==1

1 Like

Thanks but it doesnt work, theyre not disappearing is there a delay im missing here?

1 Like

Or… try using TweenService for fading?

local TweenService = game:GetService("TweenService")
local TweenAnimation = TweenInfo.new(3, Enum.EasingStyle.Linear)

function OnTouch(Boomer)
	local Explosion = Instance.new("Explosion")
	Explosion.BlastPressure = 800000
	Explosion.BlastRadius = 70
	Explosion.Parent = workspace
	Explosion.Position = script.Parent.Position
	Explosion.Hit:Connect(function(Part)
		Part.CanCollide = false
		Part.Anchored = true
		local Tween = TweenService:Create(Part, TweenAnimation, {Transparency = 1})
		Tween:Play()
		wait(3)
		Part:Destroy()
	end)
	script.Parent:Destroy()
end

script.Parent.Touched:Connect(OnTouch)
1 Like

I’m opening studio, I’ll see what I can do. Since you want a nuke effect, the radious of the explosion would be very big, as stated by yourself. So, what I recommend doing is creating a Sphere-shaped part, which by using TweenService, you can smoothly increase it’s size, and anything which touches it, gets destroyed.

1 Like

Explosion instance has Explosion.hit event.

3 Likes

This is a meteor script function so if theres delay needed to be added for the affected explosion parts the part*nuke) will continuously explode explode explode until like for .3 seconds and that is lagging too much

1 Like

Have you tried my script or not?

1 Like

Please wait, I’m reloading studio :sweat_smile:

Okay i tried but the parts r still there…

1 Like

The parts r still there :frowning: any help?

EDIT: IF Im not replying anymore I’m heading to sleep and hopefully we’ll continue this post cus its 11 PM in here and Im quite tired

1 Like

I haven’t used explosion instance for years… but maybe hit event doesn’t work because you are deleting script.Parent, which means deleting where can do something when event fired.

2 Likes

This worked:

script.Parent.Touched:Connect(function(hit)
	local Explosion = Instance.new("Explosion")
	Explosion.BlastPressure = 800000
	Explosion.BlastRadius = 70
	Explosion.Parent = workspace
	Explosion.Position = script.Parent.Position
	Explosion.Hit:Connect(function(touched)
		if touched:IsA("BasePart") then
			touched:Destroy()
		end
	end)
end)
2 Likes

Actually, it just pushed the parts away, did not delete them… Let me try to fix this.

1 Like

but now where do i have to assign its OnTouch function, should I replace the whole to this?

1 Like

There’s no need to do that. :Connect() takes a function value, and, in the way we/I did there, the same moment we used :Connect(), we created a function. That makes the function anonymous, meaning it cannot be executed any time later.

2 Likes

okay but now the meteor is bouncing around everything, deletes everything so should i put a :Destroy() after the last line?

1 Like