Need help to fix GUI close button not being responsive

  1. What do you want to achieve? fixing my script and fixing the functionality.

  2. What is the issue? I have a GUI script that opens when the player is within the vicinity of a part, and it should close when the player walks away. Along with this, there is a close button to close out the frame.

However,

The close button does not work always, and only consistently works when outside the range.

  1. What solutions have you tried so far? I have seen many scripts with the magnitude, but none with a close button on it too. I believe the problem is that the game still detects the player is in the range, so it can’t fully close out.

The above video should showcase that the GUI opens and closes, but the close button does not work.

Here is my script.

while wait() do
	if (touch.Position - character:WaitForChild("HumanoidRootPart").Position).Magnitude < 10 and isBought.Value == false then

		script.Parent:TweenPosition(UDim2.new(0.3,0,0.213,0), "In","Bounce",0.5)
		
	else
		wait()
			
		script.Parent:TweenPosition(UDim2.new(0.3,0,1.5,0), "Out","Bounce",0.5)
	end
	
	script.Parent.Frame.CloseButton.MouseButton1Click:Connect(function()		
		if canClick then		
			canClick = false
			script.Parent:TweenPosition(UDim2.new(0.3,0,1.5,0), "Out","Bounce",0.5) 
			wait(1)
			canClick = true	

		end
	end)
end

If you need me to clarify anything more, please let me know.

Hey! I was having similar issues as you, with checking if a character is in a certain vicinity, I reccomend you make a part, sphere/brick… And that will be the area.

Code;


 function getParams(char,parameterpart)
	if table.find(workspace:GetPartsInPart(parameterpart),char.PrimaryPart) then
		print(Char.Name.." found in "..parameterpart.Name)
		return true
	end
end

if getParams(character,part) == true then
    -- does what i want the script to do here
end

You can try something like this:

local justClosed = false
while wait() do
	if (touch.Position - character:WaitForChild("HumanoidRootPart").Position).Magnitude < 10 and isBought.Value == false  and not justClosed then

		script.Parent:TweenPosition(UDim2.new(0.3,0,0.213,0), "In","Bounce",0.5)
		
	else
		wait()
			
		script.Parent:TweenPosition(UDim2.new(0.3,0,1.5,0), "Out","Bounce",0.5)
        justClosed = false
	end
	
	script.Parent.Frame.CloseButton.MouseButton1Click:Connect(function()		
		if canClick then		
			canClick = false
        justClosed = true

			script.Parent:TweenPosition(UDim2.new(0.3,0,1.5,0), "Out","Bounce",0.5) 
			wait(1)
			canClick = true	
		end
	end)
end

Hi thank you both so much! Your solutions are both great, however I got my code to work using CremaOwner’s script with some modifications. Again, thank you for the help, you both are life savers :slight_smile:

2 Likes