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

Is there a problem with me using enabled, or did I just write the script wrong?

Asked by 7 years ago

I am making a script that is in a part. Within this part is the script and several Smoke. I have tried several things to get the smoke to appear and disappear after certain amount of time. I decided that I would script the smoke to turn on and off using the enabled feature of the properties. This is what I've tried, but something doesn't seem to work, as the smoke with not enable or disable after the time has passed.

01local children = workspace:GetChildren()
02if children == "Smoke" then
03a = children
04while true do
05wait(0.01) -- Don't touch
06a.Enabled = true
07wait(5) -- How long you want the smoke to stay on
08a.Enabled = false
09wait(12) -- How long you want the smoke to stay off then go back on
10end
11end

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
7 years ago
Edited 7 years ago

Edit: You would use GetDescendants as GetChildren only returns direct children

GetChildren returns an array, not a value, you would have to use pairs instead to go through each value.

However, you can just put the script inside the smoke.

1local smoke = script.Parent
2 
3while true do
4    wait(0.01) -- Don't touch
5    smoke.Enabled = true
6    wait(5) -- How long you want the smoke to stay on
7    smoke.Enabled = false
8    wait(12) -- How long you want the smoke to stay off then go back on
9end

Using GetDescendants

01local smoke
02 
03repeat wait(1)
04    for i,v in pairs(workspace:GetDescendants())do
05        if v.Name == "Smoke" and v:IsA("Smoke") then
06            smoke = v
07            break
08        end
09    end
10until smoke
11 
12while true do
13    wait(0.01) -- Don't touch
14    smoke.Enabled = true
15    wait(5) -- How long you want the smoke to stay on
16    smoke.Enabled = false
17    wait(12) -- How long you want the smoke to stay off then go back on
18end
0
This doesn't work either. Could it be that the smoke and the script have the same parent? 2sail2you 4 — 7y
0
I edited it. It should work now. UgOsMiLy 1074 — 7y
0
THANK YOU! 2sail2you 4 — 7y
Ad

Answer this question