Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

When my fireball explodes it lags for a breif second why is this?

local TS = game:GetService("TweenService")
local tool = script.Parent

local dmg = 25
	
local CanTake = true
	
tool.Clicked.OnServerEvent:Connect(function(plr, Mouse)
	
	local fireball = game.ReplicatedStorage.MagicAttacks.FIreBallParticle:Clone()
	
	
	fireball.Parent = workspace
	fireball.Name = plr.Name.." FIreBallParticle"
	fireball.Shape = Enum.PartType.Ball
	fireball.Material = Enum.Material.Neon
	fireball.Color = Color3.fromRGB(213, 115, 61)	
	fireball.Size = Vector3.new(5,5,5)
	fireball.Transparency = .3
	fireball.CanCollide = false
	game.Debris:AddItem(fireball,6)
	
	
	local pos = plr.Character.Head.Position + CFrame.new(plr.Character.Head.Position, Mouse.p).lookVector * 1 
	fireball.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,4,5)
	fireball:SetNetworkOwner(plr)
	
	
	local BodyVelocity = Instance.new("BodyVelocity",fireball)
	BodyVelocity.Velocity = Mouse.lookVector * 140
	BodyVelocity.MaxForce = Vector3.new(1e8,1e8,1e8)
	game.Debris:AddItem(fireball, 5)
	
	
	--// Hits a part \\--
	
	
	fireball.Touched:Connect(function(hit)
		if hit and not hit.Parent:FindFirstChild("Humanoid") and hit.CanCollide == true then
			local Explosion = game.ReplicatedStorage.ShockwaveStuff.Orange:Clone()
			Explosion.Parent = workspace
			Explosion.Name = plr.Name.." Orange"
			
			Explosion.CFrame = fireball.CFrame * CFrame.new(0,0,-2)
			Explosion.CanCollide = false
			Explosion.Transparency = .2
			fireball:Destroy()
			
			tool.Fireball.Explosion:Play()
			--// Shockwave \\--		
			
			local Shockwave = game.ReplicatedStorage.Shockwave:Clone()
			Shockwave.Parent = workspace
			Shockwave.Name = plr.Name.." Shockwave"
			Shockwave.CFrame = Explosion.CFrame
			
			--// SHockwave2 \\--
			
		local Shockwave2 = game.ReplicatedStorage.ShockwaveStuff.BallShockwave:Clone()
	
		Shockwave2.Parent = workspace
		Shockwave2.Name = plr.Name.." BallShockwave"
		Shockwave2.CFrame = fireball.CFrame * CFrame.new(0,0,0)
	
		Shockwave2.Orientation = Vector3.new(0, 0, 0)
			
			
			--// Explosion Tween \\--
			
			
			
			local TweeningInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(35.049, 47.862, 59.774);
			Transparency = 1}
			
			local Tween = TS:Create(Explosion, TweeningInfo, partProperties)
			Tween:Play()
			
			
			
			wait(.1)
			--// Shockwave Tween \\--
			
						
			local TweeningInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(34.049, 46.862, 58.774);
			Transparency = 1}
			
			local Tween = TS:Create(Shockwave, TweeningInfo, partProperties)
			Tween:Play()

			--// SHockwave2 \\--
	
	
			local TweeningInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(80.726, 80.72, 79.992);
			Transparency = 1;
			Orientation = Vector3.new(-50.9, -58.88, -137.36)}
			
			local Tween = TS:Create(Shockwave2, TweeningInfo, partProperties)
			Tween:Play()
			
					game.Debris:AddItem(Explosion, 2)
			game.Debris:AddItem(Shockwave, 2)
			game.Debris:AddItem(Shockwave2, 2)
			
		end
	end)
	


			
	
	--// Hits a player \\--
	
	
	fireball.Touched:Connect(function(hit)
		if hit .Parent == plr.Character then return end
		if hit and hit.Parent:FindFirstChild("Humanoid") and CanTake == true then
			local EnemyHum = hit.Parent:FindFirstChild("Humanoid")
			EnemyHum:TakeDamage(dmg)
			CanTake = false
			fireball:Destroy()
			
	
			
			--// Explosion \\--
			
			
			local Explosion = game.ReplicatedStorage.ShockwaveStuff.Orange:Clone()
			Explosion.Name = plr.Name.." Orange"
			Explosion.CFrame = fireball.CFrame
			Explosion.Parent = workspace
			Explosion.Anchored = true
			Explosion.Transparency = .2
			
			
			
			--// Shockwave \\--
			
			
			
			local Shockwave = game.ReplicatedStorage.Shockwave:Clone()
			Shockwave.Parent = workspace
			Shockwave.Name = plr.Name.." Shockwave"
			Shockwave.CFrame = Explosion.CFrame
			
			--// SHockwave2 \\--
			
		local Shockwave2 = game.ReplicatedStorage.ShockwaveStuff.BallShockwave:Clone()
	
		Shockwave2.Parent = workspace
		Shockwave2.Name = plr.Name.." BallShockwave"
		Shockwave2.CFrame = fireball.CFrame * CFrame.new(0,0,0)
	
		Shockwave2.Orientation = Vector3.new(0, 0, 0)
		
					--// Damage \\--
			
			



			
			
			--// Tweens \\--
			
			
			
			local TweeningInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(15,15,15);
			Transparency = 1}
			
			local Tween = TS:Create(Explosion, TweeningInfo, partProperties)
			Tween:Play()
			
			wait(.1)
			
			
			
			--// Shockwave Tween \\--
			
						
			local TweeningInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(14,14,14);
			Transparency = 1}
			
			local Tween = TS:Create(Shockwave, TweeningInfo, partProperties)
			Tween:Play()
			
			wait(.1)
			
	
			local TweeningInfo = TweenInfo.new(2.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
			
			local partProperties = {	
				
			Size = Vector3.new(80.726, 80.72, 79.992);
			Transparency = 1;
			Orientation = Vector3.new(-50.9, -58.88, -137.36)}
			
			local Tween = TS:Create(Shockwave2, TweeningInfo, partProperties)
			Tween:Play()
			
			CanTake = true
			game.Debris:AddItem(Explosion, 2)
			game.Debris:AddItem(Shockwave, 2)
			game.Debris:AddItem(Shockwave2, 2)
			
		
		end
	end)
	
	
	
end)

When the fireball explodes it lags like crazy for a brief second is there any way to prevent this?

2 comments

0

On line 10, are you sure the fireball is called "Fireball" and not "FIreball"? This isn't an answer, but this could help.

0

FIreball is the name of the part stored in RS

1 answer

So It could be that you don't have much memory on your PC to handle it. If you could reply to this comment with your max ram then I will try and see.

3 comments

0

I have 8 GB of ram

0

Sure

0

You didn't send a friend request to me but I sent to you

This discussion is preserved as it was. New answers, comments, and votes are closed.