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

Light switch not flipping correctly?

So I got this light switch that is supposed to flip but it doesn't.

script.Parent.MouseClick:Connect(function()
    local roof = script.Parent.Parent.Parent.Parent.Roof
    local orientation = script.Parent.Parent.Orientation
    if roof.LightToggle.Value == true then
           script.Parent.Parent.CFrame = CFrame.new(script.Parent.Parent.CFrame * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z - 60)))
        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 = CFrame.new(script.Parent.Parent.CFrame * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z + 60)))
        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)    

This script gives me the error Workspace.BedRoom.Switch.Part.ClickDetector.Script:5: bad argument #1 to 'new' (Vector3 expected, got CFrame) I know what this error means it's just I have no idea how to fix it. Any help?

5 comments

0

You are having a cframe value inside of a cframe value

0

CFrame.new(script.Parent.Parent.CFrame =CFrame.new(script.Parent.Parent.CFrame * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z - 60))))

0

multiplying a cframe by a cframe.angles gives a back a cframe

0

so just do

0

script.Parent.Parent.CFrame =CFrame.new(script.Parent.Parent.CFrame * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z - 60)))

1 answer

CFrame is inside of CFrame value. Fix it by separating the values.

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