Why doesn't this GUI open and close? Is it something to do with a studio virus?

I have one script which opens a GUI and that works perfectly, so, I thought it would be a good idea to just copy that identical script into my GUI and change the sizes. However, the second script doesn’t work whereas the first script does and I get some strange errors relating to GUIs when loading into the game (Already asked a question about this but didn’t seem to get an answer). The question is mainly about what the errors are in my game, but it’s also a check to see if I have made a mistake in my code.

Here is the screenshot of the errors which are shown when joining: https://gyazo.com/adfc270e8c6f78f05f5850a3a7180456

Here is the code:

-- // variables //
local MainFrame = script.Parent.MainFrame
local Close = script.Parent.Open


-- // functions //
local function OpenGui()
	MainFrame.Visible = true
	MainFrame.AnchorPoint = Vector2.new(0.5,0.5)
	MainFrame:TweenSize(UDim2.new(0.474, 0,0.58, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.2)
end

local function CloseGui()
	MainFrame.AnchorPoint = Vector2.new(0.5,0.5)
	MainFrame:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.2)
	wait(0.2)
	MainFrame.Visible = false
end


-- // events //
script.Parent.Open.MouseButton1Click:Connect(function()
	if MainFrame.Size == UDim2.new(0.474, 0, 0.58, 0) then
		CloseGui()
	else
		OpenGui()		
	end
end)

Close.MouseButton1Click:Connect(CloseGui)

I did have a sudden dealing with a studio virus, so there may still be remnants of the virus which I am still not sure about. However, simply just moving place would not be ideal at all, as I have data that is saved on data stores. I have not used any free models if you’re wondering, and all of my plugins are from trusted developers. This makes me question about where they have come from.

This was the beginning of a malicious script that I found (I can’t post the whole thing as it was on one line) which I managed to remove as it was teleporting me to a different place, this issue was resolved by simply deleting the script.

EDIT 2: I have noticed that when joining the game, it seems to show as if my character is taking damage and the screen flashes red for a fraction of a second.

Try adding a Debounce and a different check without the use of size:

-- // variables //
local MainFrame = script.Parent.MainFrame
local Close = script.Parent.Open

local Visible = false
local Debounce = false

-- // functions //
local function OpenGui()
	MainFrame.Visible = true
	MainFrame.AnchorPoint = Vector2.new(0.5,0.5)
	MainFrame:TweenSize(UDim2.new(0.474, 0,0.58, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.2)
end

local function CloseGui()
	MainFrame.AnchorPoint = Vector2.new(0.5,0.5)
	MainFrame:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.2)
	wait(0.2)
	MainFrame.Visible = false
end


 -- // events //
script.Parent.Open.MouseButton1Click:Connect(function()
	if not Debounce then
		Debounce = true

		if Visible then
			CloseGui()
			Visible = false
		else
			OpenGui()
			Visible = true	
		end

		wait(.5)
		Debounce = false
	end
end)

Close.MouseButton1Click:Connect(CloseGui)

Edit: formatting is messing up ¯_(ツ)_/¯

If the problem was not having a debounce it would give me a different error. If I simply just close the GUI and wait a few seconds it still won’t open. However, I will give your script a go.

Edit: Same error is still persisting.

I knew the Debounce wouldn’t be the issue but try my other suggested approach; using a Boolean instead of the Size to tell if it’s closed or not.

I don’t get why it would be any different to my other script though, it is literally exactly the same rather than the location of the ‘Open’ button and that’s it, and the other one works perfectly fine.

Edit: Also, the sizing of the GUI is actually working perfectly fine as I have just realised, the GUI just isn’t showing. Also, if you look at the errors that I am currently getting it says something to do with CoreGui, this could be causing some problems.

Edit2: The errors aren’t anything to do with that actual GUI, it is to do with something the game. I will move the GUI to another place and see if that is affecting anything.

Edit3: Now I’m even more confused, when loading into even a different game instance I still seem to be getting the error. I will discard my changes and remove the GUI that I moved into studio.My Roblox studio also seemed to crash at the exact moment.

Yeah those errors are weird, I’m getting them in any other Studio game I join too.

Ah, it must be a Roblox bug then. I’m sure that it will be fixed soon, hopefully, I have a feeling that’s what’s affecting my UI’s as it’s an error in the CoreGui. However, I’m not 100% on that and it’s just a speculation.

Add the script INTO the GUI, or add the script INTO a block.
Try one of these.

The script already is in the GUI hence why I’ve done ‘script.Parent.’

"MouseButton1Click is wrong, It should be “MouseButtonClick = 1”
I don’t know much but its probably that.

The gui also has to be a button.

The correct event is ‘MouseButton1Click’, the GUI also is a button. As I’ve said, the script has worked correctly somewhere else, but I will just to see if it’s the recent Roblox bugs that is causing the problems first.

Reference: https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

1 Like