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

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

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.

local children = workspace:GetChildren()
if children == "Smoke" then
a = children
while true do
wait(0.01) -- Don't touch
a.Enabled = true
wait(5) -- How long you want the smoke to stay on
a.Enabled = false
wait(12) -- How long you want the smoke to stay off then go back on
end
end

1 answer

✓ Accepted answer

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.

local smoke = script.Parent

while true do
	wait(0.01) -- Don't touch
	smoke.Enabled = true
	wait(5) -- How long you want the smoke to stay on
	smoke.Enabled = false
	wait(12) -- How long you want the smoke to stay off then go back on
end

Using GetDescendants

local smoke

repeat wait(1)
	for i,v in pairs(workspace:GetDescendants())do
		if v.Name == "Smoke" and v:IsA("Smoke") then
			smoke = v
			break
		end
	end
until smoke

while true do
	wait(0.01) -- Don't touch
	smoke.Enabled = true
	wait(5) -- How long you want the smoke to stay on
	smoke.Enabled = false
	wait(12) -- How long you want the smoke to stay off then go back on
end

3 comments

0

This doesn't work either. Could it be that the smoke and the script have the same parent?

0

I edited it. It should work now.

0

THANK YOU!

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