How to i make a part explode

local part = script.Parent
local debounce = true

function Explode(hit)
local hum = hit.Parent:FindFirstChild(“Humanoid”)
if hum and debounce then
debounce = false
for ExplodeWait = 1, 6 do
wait(1)
part.BrickColor = BrickColor.new(“Really red”)
wait(1)
if ExplodeWait <=2 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.7)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.7)
if ExplodeWait <=4 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.5)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.5)
if ExplodeWait <=6 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.3)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.3)
if ExplodeWait <=8 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.2)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.2)
if ExplodeWait <=10 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.1)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.1)
Explode()
end
end

				end
				
				
				
				
		
			end
			
		end
		
	end
end

end

part.Touched:Connect(Explode)

Everything in the code works fine except for the “Explode()”

Im pretty sure there’s a built in function for Explode() but thats either not the case or im not using it correctly.

2 Likes

What’s not working exactly? Do you want an explosion object to appear, or is the part not ‘exploding’ twice? If it’s the latter, you may want to set debounce back to true near the bottom of your Explode function before you call it again.

oh wait 2 things:
1: it doesnt seem to be exploding at all
2: its not supposed to be repeating twice so i am very much confused by that

Do you mean you can’t visually see an explosion? If not, you can make an Explosion object for that.

That’s because you called your function Explode inside of itself. You can remove that line of code if you don’t want it to repeat

1: alright ill do that
2: where did i call Explode? if its “Explode()” removing it seems to still making the script run twice

Right here, near the bottom of your Explode function.

Removing that still makes the script run twice and i dont know why.

What do you mean by the script running twice?

This is the script i have right now (after some changes) local part = script.Parent
local debounce = true
local Explosion = Instance.new(“Explosion”)

function ExplodeFunction(hit)
local hum = hit.Parent:FindFirstChild(“Humanoid”)
if hum and debounce then
debounce = false
for ExplodeWait = 1, 10 do
wait(1)
part.BrickColor = BrickColor.new(“Really red”)
wait(1)
if ExplodeWait <=2 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.7)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.7)
if ExplodeWait <=4 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.5)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.5)
if ExplodeWait <=6 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.3)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.3)
if ExplodeWait <=8 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.2)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.2)
if ExplodeWait <=10 then
part.BrickColor = BrickColor.new(“Black”)
wait(0.1)
part.BrickColor = BrickColor.new(“Really red”)
wait(0.1)
local Explosion = Instance.new(“Explosion”)
Explosion.Parent = game.workspace
Explosion.Position = part.Position
end
end
end

				end
				
				
				
				
		
			end
			
		end
		
	end
end

part.Touched:Connect(ExplodeFunction)

appearantly the script still runs twice (completes doing it once then just does it again) I dont know if im not understanding anything or

local part = script.Parent
local debounce = false

function ExplodeFunction(hit)
	if debounce then
		return
	end
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		debounce = true
		for ExplodeWait = 1, 10 do
			task.wait(0.5)
			part.BrickColor = BrickColor.new("Really red")
			task.wait(0.5)
			part.BrickColor = BrickColor.new("Black")
		end
		local Explosion = Instance.new("Explosion")
		Explosion.Parent = part
		Explosion.Position = part.Position
	end
	task.wait(3)
	debounce = false
end

part.Touched:Connect(ExplodeFunction)

That’s because the debounce hadn’t been setup correctly, also you don’t need to create an Explosion instance at the top of the script also I’ve translated the for loop into a much more concise version.

2 Likes
local part = script.Parent
local debounce = true
local WaitTime = 1

function ExplodeFunction(hit)
	if debounce then
		return
	end
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		debounce = true
		for ExplodeWait = 1, 10 do
		task.wait(WaitTime)
		part.BrickColor = BrickColor.new("Really red")
		task.wait(WaitTime)
		if ExplodeWait <=3 then
			WaitTime = 0.8
			if ExplodeWait <=4 then
				WaitTime = 0.6
				if ExplodeWait <=5 then 
					WaitTime = 0.5
					if ExplodeWait <=7 then
						WaitTime = 0.4
						if ExplodeWait <=9 then
							ExplodeWait = 0.2
							end
						end
					end
				end
			end
		end
	end
end
		

part.Touched:Connect(ExplodeFunction)

apparently the code you gave me earlier doesnt work. I changed to code to have the Wait time get faster but i think its something to do with "if debounce then return." If i remove that script, the script works but without a debounce, so i am very confused

also another thing is if i DO delete the “if debounce return” the code works but the ball color just changes VERY fast without waiting 0.9 seconds or anything below that

oh nevermind i got it to work. Its just that im pretty sure your variable for debounce should of been false at the start

Thanks a lot for the help though!

Yeah it should have been, I copied the code from your original post in which it was set to true.

oh yeah thats definitely my fault sorry about that1

The way you’re changing colors doesn’t work. I’ve tried the same method with changing the time in roblox.

I haven’t tried it yet and if I do I’ll come back here but set and array with the order of colors you want and with this pseudo-ish code set something up

local Colors = {"Red", "Green", "Blue"}

local TweenService = game:GetService("TweenService")
local TweenInf = TweenInfo.new(1)
local TweenGoal  ={}

for _, Color in pairs(Colors) do 
    TweenGoal.Color = Color
    local ChangeColorTween = TweenService:Create(Part, TweenInf, TweenGoal)
    ChangeColorTween:Play()
end

I haven’t tried this yet but one error I would imagine happening is the Tween not finishing before the next For loop stage or nothing happens.

local part = script.Parent
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
explosion.BlastRadius = 10
explosion.BlastPressure = 100000
explosion.DestroyJointRadiusPercent = 0
part:Destroy()

Something like that …

As I know, you need to write :Destroy() in the end of the part location.