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

How to Check FOR something that Hasn't been Added Yet?

Asked by 6 years ago
Edited 6 years ago

For Example,

I have a thing in Lighting called LIGHT

script.Parent.Touched:Connect(function()

morelight = Instance.new("ColorCorrectionEffect",game.Lighting)

morelight.Brightness = .4

morelight.Name = "LIGHT"

end)

that's what happens, but I want it to not add more than one of it otherwise it blinds the screen.

so when I put an if statement before the code like this:

script.Parent.Touched:Connect(function()

if game.Lighting.LIGHT then return end

...

end)

to check whether LIGHT already exists and not do anything it says LIGHT is not a valid member of Lighting which is pretty self-explanitory.

However, I just don't know what to do.

Firstly, I don't need debounce because it would still add more.

Secondly, I don't need Debris because I want LIGHT to stay.

1 answer

Log in to vote
0
Answered by
TheePBHST 154
6 years ago
if not game.Lighting:FindFirstChild("LIGHT") then
    --code
end
0
Didn't mention but I already tried that and it says the same thing dareveloper 9 — 6y
0
sorry i didnt put the findfirstchild i didnt know it makes a difference till now dareveloper 9 — 6y
0
Well, yeah either WaitForChild or FindFirstChild could prevent your error. TheePBHST 154 — 6y
0
thanks waitforchild would have been the obvious one lol dareveloper 9 — 6y
Ad

Answer this question