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

Why won't my simple code work? Light Switch [ANSWERED]

Asked by 5 years ago
Edited 5 years ago

Why won't this simple code work? It keeps teleporting Switch up a stud. idk why.

local xori = script.Parent.Switch.Orientation.X
local yori = script.Parent.Switch.Orientation.Y
local zori = script.Parent.Switch.Orientation.Z

function onClicked()
        if script.Parent.Switch.Orientation.Z == 90 then 
    script.Parent.Parent.CeilingLight.Light.SurfaceLight.Brightness = 0
    script.Parent.Switch.Orientation = Vector3.new(xori, yori, zori + 4)
else
    script.Parent.Parent.CeilingLight.Light.SurfaceLight.Brightness = 3
    script.Parent.Switch.Orientation = Vector3.new(xori, yori, zori)
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
0
Answered by 5 years ago
local Light = script.Parent.Parent.CeilingLight.Light.SurfaceLight
local Switch = script.Parent.Switch
local on, off = Switch.CFrame * CFrame.Angles(0, 0, math.rad(2)),   Switch.CFrame * CFrame.Angles(0, 0, -math.rad(2)) 

local function onClicked()
    if Light.Brightness == 3 then
      Light.Brightness = 0
      Switch.CFrame = on
  else
    Light.Brightness = 3
    Switch.CFrame = off
  end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)
Ad

Answer this question