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

Button destroys fire instance first time, but doesn't do it second time?

So I made a button that was supposed to revert the object's color back to the original color, and also remove any fire instances from the object. The thing is, the button works, but only when you click it the first time. It changes the color, but only deletes the fire instance once, after that it doesn't work.

This is the script:

local tweenBall = workspace.TweenButton.Part
local detectBallColor = tweenBall.Parent.DetectPartColor
local fire = tweenBall:WaitForChild("Fire")

local button = script.Parent
local isClicked = nil
local isChanged = nil

button.ClickDetector.MouseClick:Connect(function(player)
	
	if not isClicked then
		
		isClicked = true
		
		if fire or tweenBall.Color ~= detectBallColor.Color then
			
			if not isChanged then
				
				isChanged = true
				fire:Destroy()
			
				print("Fire destroyed")
			
				tweenBall.Color = detectBallColor.Color
				print("Color changed")
			
				wait(3)
				isClicked = false
				isChanged = false
			else
				
				isClicked = true
				
				
			end
			
			
		end
	end
end)

I tried changing some things, but it doesn't work

Any help would be appreciated

1 answer

local tweenBall = workspace.TweenButton.Part
local detectBallColor = tweenBall.Parent.DetectPartColor
local fire = tweenBall:WaitForChild("Fire")

local button = script.Parent
local isClicked = nil
local isChanged = nil

button.ClickDetector.MouseClick:Connect(function(player)

    if not isClicked then

        isClicked = true

        if fire or tweenBall.Color ~= detectBallColor.Color then

            if not isChanged then

                isChanged = true
                fire:Destroy()

                print("Fire destroyed")

                tweenBall.Color = detectBallColor.Color
                print("Color changed")

                wait(3)
                isClicked = false
                isChanged = false
            else

                isClicked = false -- changed to false


            end


        end
    end
end)

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