Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Can someone help me fix this?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
0
Answered by 10 years ago
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.

Ad
Log in to vote
0
Answered by
Andalf 100
10 years ago

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)
0
That script works, but I'm trying to run it through an on/off button. How can that change to make that work? Pawsability 65 — 10y
0
Just change script.Parent.Part to the path of the part that contains your smoke :). Andalf 100 — 10y

Answer this question