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

What is wrong with my script?

I tried to make a sphere bulb that turns on and off. The sphere was put under workspace and i inserted a script and a PointLight into it...... Here is the code I had trouble with it says line 6 is the problem...

 lightupsphere = script.Parent
--print(lightupsphere)--was used as test
while true do 
	for i,v in pairs(lightupsphere:getChildren()) do
		if(v~=script) then
		v.Sphere.PointLight.Enabled = not v.Sphere.PointLight.Enabled    
		end
	end
	wait(2)
end

3 answers

✓ Accepted answer

Assuming lightupsphere is the sphere with the light in it:

v in line 4 is a child of lightupsphere. That would make it either the script or the PointLight.

You don't need v.Sphere.PointLight -- the PointLight is v.

v.Enabled = not v.Enabled


(While this is not wrong in your script) It would be a better check, rather than v ~= script to actually require that v is a light:

if v:IsA("Light") then
-- Light is a super-class for PointLight and SpotLight

@Andrew ... Your script doesnt even work lol the other guys fix is all that was needed read his did you even test it lol

lightupsphere = script.Parent
\
--print(lightupsphere)--was used as test

while true do

    for i,v in pairs(lightupsphere:getChildren()) do

        if v:IsA("Light") then

        v.Sphere.PointLight.Enabled = v.Sphere.PointLight.Disabled  

        end

    end

    wait(2)

end

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