I currently have a problem with a toggleable switch where I will tween it and it will work but if I rotate it and then tween it, the tween goes in the same exact position.
This is the current code:
-- variables
local part = script.Parent
local clickDetector = part.Parent.ClickDetector
local tweenService = game:GetService("TweenService")
local sound = part.Parent.Sound
-- positions
local switchpos = part.Position
local target1 = part.Orientation + Vector3.new(35, 0, 0)
local target2 = part.Orientation + Vector3.new(-35, 0, 0)
-- nil variables
local pos = 0
local debounce = false
-- tweeninfo
local tweenInfo = TweenInfo.new(
0.1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
-- tweening
local goal1 = {}
goal1.Orientation = target1
local goal2 = {}
goal1.Orientation = target2
local tween = tweenService:Create(part, tweenInfo, goal2)
local rtween = tweenService:Create(part, tweenInfo, goal1)
-- click/tween
clickDetector.MouseClick:Connect(function()
-- tween edit
switchpos = part.Position
target1 = part.Orientation + Vector3.new(70, 0, 0)
target2 = part.Orientation + Vector3.new(-70, 0, 0)
goal1.Orientation = target1
goal2.Orientation = target2
tween = tweenService:Create(part, tweenInfo, goal1)
rtween = tweenService:Create(part, tweenInfo, goal2)
-- pos 0
if pos == 0 and debounce == false then
debounce = true
sound:Play()
tween:Play()
pos = 1
wait(0.35)
debounce = false
-- pos 1
elseif pos == 1 and debounce == false then
debounce = true
sound:Play()
rtween:Play()
pos = 0
wait(0.35)
debounce = false
end
end)