You're setting a Position (a Vector3) to a CFrame. CFrames aren't Vector3s, so you can't do that.
To get the position of a CFrame, use its .p property -- read the wiki.
However, it would be better to set the CFrame, rather than set the Position, because Position behaves rather poorly.
Thus the best solution would simply be
function onClicked()
local on = script.Parent.Vector3.On
local off = script.Parent.Vector3.Off
if script.Parent.Position == off.Value then
script.Parent.CFrame = CFrame.new(on.Value)
end
if script.Parent.Position == on.Value then
script.Parent.CFrame = CFrame.new(off.Value)
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Remember to tab your code correctly
Of course, it's not a good idea to compare the Positions, or to compare to on and off when they're opposites. Use a boolean variable:
local on = false
function onClicked()
local go
if on then
go = script.Parent.Vector3.On
else
go = script.Parent.Vector3.Off
end
script.Parent.CFrame = CFrame.new(go.Value)
on = not on
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
1 comment
Look at my script again, your script is different. Take the off value and stuff and replace "0,0,0" in "CFrame.new(0,0,0) --[[Off value]]". Same with the On Value one.