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

Why won't the blur start when enabled?

Asked by
Comqts 6
2 years ago
local touchpart = game.Workspace.GasChamber.Touchpart
local blur = game.Lighting.GasBlur
local model = game.Workspace.GasChamber.gas:GetChildren()

touchpart.Touched:Connect(function()
    for i,v in pairs(model) do
        while wait(2) do -- I put this here to constantly check if the smoke is enabled/disabled
            if v.Smoke.Enabled == false then
                blur.Enabled = false
            else
                if v.Smoke.Enabled == true then
                    blur.Enabled = true
                end
            end
        end
    end 
end)

With my previous question, I got the part to move, now I have one problem. The blur won't start when the touch part is detected. It is in StarterCharacterScripts as a Local Script, so I don't get what the problem is.

0
Can you put prints in the code to check if it's running? DocGooseYT 110 — 2y

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
2 years ago
Edited 2 years ago

wrong stuff:

use getservice for services (lighting, players and stuff are all services, not just the ones with service at the end of their names, you can use workspace instead of game.Workspace btw)

while wait(2) is unnecessary. you can just use v.Smoke:GetPropertyChangedSignal("Enabled")

use task.wait() instead of wait(), they are basically the same except task.wait() is more accurate, in fact it is meant to replace wait.

use ipairs instead of pairs for arrays, and use pairs for dictionaries

-- array:
local array = {"something", "something else", "idk"}

-- dictionary:
local dictionary = {["thing"] = "thing", ["workspace"] = workspace, ["weird"] = "insert thing here"}

fixed script:

local gc = workspace.GasChamber
local p = gc.Touchpart
local blur = game:GetService("Lighting").GasBlur
local model = gc.gas
local smok = model.(idk what the parts are called so edit this).Smoke

blur.Enabled = smok.Enabled -- yes you can do this
smok:GetPropertyChangedSignal("Enabled"):Connect(function()
    blur.Enabled = smok.Enabled
end)

p.Touched:Connect(function(hit) -- i am gonna assume you want it to activate only if a player steps in (delete line 13 and line 17 if you allow the thing to activate from all blocks)
    if game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) then
        for i,v in ipairs(model:GetChildren()) do -- :GetChildren() and :GetDescendants() always returns arrays
            v.Smoke.Enabled = true
        end
    end
end)
Ad

Answer this question