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

PointLight is not a valid member of Part?

Asked by 9 years ago

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.

01lightOn = false
02SmoothBlockModel = script.Parent
03 
04function onClicked()
05    if lightOn == false then
06        local l = Instance.new("PointLight")
07        l.Brightness = 4
08        l.Range = 5
09        l.Parent = script.Parent
10        lightOn = true
11    end
12    if lightOn == true then
13         script.Parent.PointLight:Destroy()
14 
15    end
16 
17 
18end
19 
20script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 answers

Log in to vote
0
Answered by 9 years ago
01lightOn = false
02SmoothBlockModel = game.Workspace.SmoothBlockModel--for more effectiveness
03 
04function onClicked()
05    if lightOn == false then
06        local l = Instance.new("PointLight")
07        l.Brightness = 4
08        l.Range = 5
09        l.Parent = SmoothBlockModel --Use your variables
10        lightOn = true
11    if lightOn == true then
12   if SmoothBlockModel:findFirstChild("PointLight") then SmoothBlockModel.PointLight:Destroy()
13end
14end --Also leave all your ends together to make sure it runs all together.
15end
16end
17 
18SmoothBlockModel.ClickDetector.MouseClick:connect(onClicked)

If this helped which I hope it did be sure to accept it.

0
This would still break, LOL DevChris 235 — 9y
0
It wouldnt actually legomaster38 39 — 9y
0
Dont dj legomaster38 39 — 9y
0
Dont disrespect other peoples work. Or themselves follow the community guidelines.* legomaster38 39 — 9y
Ad
Log in to vote
0
Answered by
DevChris 235 Moderation Voter
9 years ago

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.

01local on = false
02local block = script.Parent -- Make sure the script's parent actually is a block.
03 
04block.ClickDetector.MouseClick:connect(function() -- Try to minimize your functions.
05    if not on then -- "not" is a quick way of saying "if variable == false"
06        local pointLight = Instance.new("PointLight", block) -- We can set the parent in the same function
07        pointLight.Brightness = 4
08        pointLight.Range = 5
09        on = true
10    elseif on then -- Get rid of not and it means "if variable == true"
11        if block:FindFirstChild("PointLight") then -- If a PointLight exists in the block
12            block.PointLight:Destroy()
13        end
14    end
15end)
0
Make sure it's a script, the parent is a block and there is a ClickDetector. DevChris 235 — 9y

Answer this question