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

Light switch disappearing when flipped?

Asked by 5 years ago
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?

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 User#27525 1 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
0
it didnt work. no output, the switch still disappears when pressed. DaBrainlessOne 129 — 5y
Ad

Answer this question