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

Light switch disappearing when flipped?

script.Parent.MouseClick:Connect(function()
	local roof = script.Parent.Parent.Parent.Parent.Roof
	if roof.LightToggle.Value == true then
 	script.Parent.Parent.CFrame = script.Parent.Parent.CFrame * CFrame.new(-21.9, 4.642, 17.77) * CFrame.Angles(0, math.rad(90), math.rad(138.23))
		for a, b in pairs(roof:GetChildren()) do
			if b.Name == ("Light") then
				b.PointLight.Enabled = false
				b.Material = Enum.Material.Plastic
			end
		end
		roof.LightToggle.Value = false
	elseif roof.LightToggle.Value == false then
		script.Parent.Parent.CFrame = script.Parent.Parent.CFrame * CFrame.new(-21.9, 4.642, 17.77) * CFrame.Angles(0, math.rad(90), math.rad(-126.43))
		for a, b in pairs(roof:GetChildren()) do
			if b.Name == ("Light") then
				b.PointLight.Enabled = true
				b.Material = Enum.Material.Neon
			end
		end
		roof.LightToggle.Value = true
	end
end)

so this is a light switch that's supposed to flip up and down and turn the lights on and off. the lights work perfectly except the switch disappears after i click it once. any help?

1 comment

0

If my answer don't work, it's probably because you're trying to do 2 movements at once. Use tween instead, here's a good answer, you just have to modify: https://scriptinghelpers.org/questions/82114/how-to-rotate-a-part-with-tweening

1 answer

Found 2 errors related to math.rad in the code. Here's the script:

script.Parent.MouseClick:Connect(function()
    local roof = script.Parent.Parent.Parent.Parent.Roof
    if roof.LightToggle.Value == true then
    script.Parent.Parent.CFrame = script.Parent.Parent.CFrame * CFrame.new(-21.9, 4.642, 17.77) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(138.23))
        for a, b in pairs(roof:GetChildren()) do
            if b.Name == ("Light") then
                b.PointLight.Enabled = false
                b.Material = Enum.Material.Plastic
            end
        end
        roof.LightToggle.Value = false
    elseif roof.LightToggle.Value == false then
        script.Parent.Parent.CFrame = script.Parent.Parent.CFrame * CFrame.new(-21.9, 4.642, 17.77) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(-126.43))
        for a, b in pairs(roof:GetChildren()) do
            if b.Name == ("Light") then
                b.PointLight.Enabled = true
                b.Material = Enum.Material.Neon
            end
        end
        roof.LightToggle.Value = true
    end
end)

1 comment

0

it didnt work. no output, the switch still disappears when pressed.

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