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.
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.
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.
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
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.