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 8 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.


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)

2 answers

Log in to vote
0
Answered by 8 years ago
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.

0
This would still break, LOL DevChris 235 — 8y
0
It wouldnt actually legomaster38 39 — 8y
0
Dont dj legomaster38 39 — 8y
0
Dont disrespect other peoples work. Or themselves follow the community guidelines.* legomaster38 39 — 8y
Ad
Log in to vote
0
Answered by
DevChris 235 Moderation Voter
8 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.

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)
0
Make sure it's a script, the parent is a block and there is a ClickDetector. DevChris 235 — 8y

Answer this question