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

Can someone help me fix this?

This doesn't seem to be working and I don't really understand why. I looks fine to me.

function OnClicked()
	script.Parent.Parent.SmokeMachine.Enable = true
	wait(0.25)
	script.Parent.Parent.SmokeMachine.Color = Color3.new(math.random(), math.random(), math.random())
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Also, how would I make it so that turns off too?

2 answers

script.Parent.Parent.SmokeMachine.Enabled = true

The correct property is called 'Enabled' you have 'Enable'.

If you want to be able to turn it off and on, I'd recommend just putting a simple boolean at the top I'll show you here:

smoke = false
function OnClicked()
	if smoke == "false" then
		script.Parent.Parent.SmokeMachine.Enabled = true
		wait(0.25)
		script.Parent.Parent.SmokeMachine.Color = Color3.new(math.random(),math.random(),math.random())
		smoke = true
	elseif smoke == "true" then
		script.Parent.Parent.SmokeMachine.Enabled = false
		smoke = false
	end
end

That should help it. The changing color of the smoke will only change once unless you turn it off and turn it back on again.

Assuming SmokeMachine is just a Smoke object, here's some better code

script.Parent.ClickDetector.MouseClick:connect(function()
		if script.Parent.Smoke.Enabled then
			script.Parent.Smoke.Enabled = false			
		else
			script.Parent.Smoke.Enabled = true
			wait(.25)
			script.Parent.Smoke.Color = Color3.new(math.random(), math.random(), math.random())
		end
end)

To make it turn off I checked if it's already enabled, if it is, turn it off else turn it on, wait .25 seconds and turn a random colour.

The way this is laid out is as such

Workspace
-Part
--Smoke
--ClickDetector
--Script (Code goes in here)

2 comments

0

That script works, but I'm trying to run it through an on/off button. How can that change to make that work?

0

Just change script.Parent.Part to the path of the part that contains your smoke :).

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