Stop a tween when a GUI is opened

i am trying to make a tween to pause when a gui is opened and will play again after the gui is closed, the problem is the script wont work and the tween itself wont play (after i put the “if button” script)

local TweenService = game:GetService(“TweenService”)
local Fumo = script.Parent
local button = game.StarterGui.Settings.Scrolling

local Info = TweenInfo.new(
0.2, --speed
Enum.EasingStyle.Quad, --easing style
Enum.EasingDirection.Out, --easing direction
-1, --repeating (-1 to continue for evah)
true, – repeat?
0) --delay before start

local Sizee = {Size = Vector3.new(6.003, 5.093, 6.887)}
–no change, -1.300, +1.300

local tween = TweenService:Create(Fumo, Info, Sizee)

tween:Play()

if button.Visible == true then
tween:Pause()
elseif button.Visible == false then
tween:Resume()
end

You could just do:

button:GetPropertyChangedSignal("Visible"):Connect(function()
     if button.Visible then
          tween:Pause()
     else
          tween:Play()
     end
end)
1 Like

Visible is a boolean, I don’t need to compare it’s value to another boolean. It’s either true or false on its own.

1 Like

My bad, I apologize. (30 letters)

The problem might because of that your script is checking if a button is visible inside of starter gui, not player gui, also is there any errors on the output?

im so sorry for not checking my notification and being very late
but nope, i dont get any error on my output