I am trying to make a light on and light off script but I can't remember how to make it so the script waits for the light to be created.
lightOn = false SmoothBlockModel = script.Parent function onClicked() if lightOn == false then local l = Instance.new("PointLight") l.Brightness = 4 l.Range = 5 l.Parent = script.Parent lightOn = true end if lightOn == true then script.Parent.PointLight:Destroy() end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
lightOn = false SmoothBlockModel = game.Workspace.SmoothBlockModel--for more effectiveness function onClicked() if lightOn == false then local l = Instance.new("PointLight") l.Brightness = 4 l.Range = 5 l.Parent = SmoothBlockModel --Use your variables lightOn = true if lightOn == true then if SmoothBlockModel:findFirstChild("PointLight") then SmoothBlockModel.PointLight:Destroy() end end --Also leave all your ends together to make sure it runs all together. end end SmoothBlockModel.ClickDetector.MouseClick:connect(onClicked)
If this helped which I hope it did be sure to accept it.
I'll rewrite it for you. Don't declare variables and not use them. Legomaster38 is trying to enforce his own scripting rules on to you too - don't listen to him.
local on = false local block = script.Parent -- Make sure the script's parent actually is a block. block.ClickDetector.MouseClick:connect(function() -- Try to minimize your functions. if not on then -- "not" is a quick way of saying "if variable == false" local pointLight = Instance.new("PointLight", block) -- We can set the parent in the same function pointLight.Brightness = 4 pointLight.Range = 5 on = true elseif on then -- Get rid of not and it means "if variable == true" if block:FindFirstChild("PointLight") then -- If a PointLight exists in the block block.PointLight:Destroy() end end end)