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

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

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

✓ Accepted answer
if not game.Lighting:FindFirstChild("LIGHT") then
	--code
end

4 comments

0

Didn't mention but I already tried that and it says the same thing

0

sorry i didnt put the findfirstchild i didnt know it makes a difference till now

0

Well, yeah either WaitForChild or FindFirstChild could prevent your error.

0

thanks waitforchild would have been the obvious one lol

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