Script not detecting the change on BoolValue

In my game, I am adding an ATM system to the game, I am doing this by having the UI contain a BoolValue that dictates whether the UI is open or closed, and a localscript that checks if the value is changed, and if it is, tweens the UI onto the screen, and when it is closed, tweens it off of the screen and sets visible to false.

The problem that I’m having is, the script is triggering correctly on the first opening of the UI, and then allowing it to close, but then afterwards is not allowing the UI to show again.

Code

Here is the LoclScript for the script that triggers when the BoolValue is changed

local TweenService = game:GetService("TweenService")
local isVisible = script.Parent.isVisible

isVisible.Changed:Connect(function()
	if isVisible.Value == false then
		local TweenInfo = TweenInfo.new(2)
		
		local goal = {}
		goal.Position = UDim2.new(0.5,0,2,0)
		
		local CloseTween = TweenService:Create(script.Parent, TweenInfo, goal)
		
		CloseTween:Play()
		
		CloseTween.Completed:Connect(function()
			script.Parent.Visible = false
		end)
	else
		script.Parent.Visible = true
		script.Parent.Position = UDim2.new(0.5,0,2,0)
		
		local TweenInfo = TweenInfo.new(2)
		
		local goal = {}
		goal.Position = UDim2.new(0.5,0,0.5,0)
		
		local OpenTween = TweenService:Create(script.Parent, TweenInfo, goal)
		
		OpenTween:Play()
	end
end)

script.Parent.CloseButton.MouseButton1Click:Connect(function()
	script.Parent.isVisible.Value = false
end)

Here is the Script under the click detector to set the BoolValue to true

script.Parent.MouseClick:Connect(function(player)
	player.PlayerGui.ATMSystem.ATMFrame.isVisible.Value = true
end)

It’s because when you disable the GUI on the client, the server still believes the GUI is enabled. The next time you click the button, the GUI is not set to enabled, because the server already thinks the GUI is enabled.

A solution would be to change your script into a LocalScript under your GUI, which would be easier to edit and manage later on.

2 Likes
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(2)

local visible = false

script.Parent.MouseClick:Connect(function()
    if visible == false then
        visible = true

        ts:Create(script.Parent, ti, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
    end
end)

script.Parent.CloseButton.MouseButton1Click:Connect(function()
    visible = false

    ts:Create(script.Parent, ti, {Position = UDim2.new(0.5, 0, 2, 0)}):Play()
end)

This should work.

The first function opens the ui, the 2nd function listens for when the player closes the ui.