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?
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)