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

Light switch not flipping correctly?

Asked by 5 years ago

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?

0
You are having a cframe value inside of a cframe value starmaq 1290 — 5y
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)))) starmaq 1290 — 5y
0
multiplying a cframe by a cframe.angles gives a back a cframe starmaq 1290 — 5y
0
so just do starmaq 1290 — 5y
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))) starmaq 1290 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question