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

PointLight is not a valid member of Part?

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

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.

4 comments

0

This would still break, LOL

0

It wouldnt actually

0

Dont dj

0

Dont disrespect other peoples work. Or themselves follow the community guidelines.*

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)

1 comment

0

Make sure it's a script, the parent is a block and there is a ClickDetector.

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