Hello, I am having trouble with this script.
It’s a local script and it’s supposed to tween a commands frame into visible and invisible, it works all fine, but when it’s visible, you need to click twice to hide it, can someone please help me and tell me why this si happening?
local TweenService = game:GetService("TweenService")
local object = script.Parent.Parent.Commands
-- define the target positions and tween infos for the two tweens
local targetPosition = UDim2.new(0.003, 0,0.7, 0 ) -- visible
local tweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)
local targetPosition2 = UDim2.new(-0.2, 0,0.7, 0) -- invisible
local tweenInfo2 = TweenInfo.new(.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)
-- create the two tweens
local tween = TweenService:Create(object, tweenInfo, {Position = targetPosition})
local tween2 = TweenService:Create(object, tweenInfo2, {Position = targetPosition2}) -- invi
-- define the event handler for the button click
script.Parent.MouseButton1Click:Connect(function()
-- check whether the object is already at the first target position
if object.Position == targetPosition then
-- start the second tween to move the object to the second target position
tween2:Play()
else
-- start the first tween to move the object to the first target position
tween:Play()
end
end)