MouseButton1Up Function not working?

Im tryna make a frame open when clicked a button, but it wont work. Why doesn’t my script work?

local mainframe = sgui:FindFirstChild("MainFrame")
local buttons = mainframe:FindFirstChild("Buttons")
local updatebutton = buttons:FindFirstChild("UpdatesButton")
local openframe = updatebutton:FindFirstChild("UpdatesLog")

openframe.Visible = false
updatebutton.MouseButton1Up:Connect(function()
	openframe.Visible = true
end)

This is my only error
Players.killersfatality.PlayerGui.MainMenuGUI.UpdatesLogOPEN:7: attempt to index nil with 'Visible'

1 Like

Try replacing this with:

updatebutton.MouseButton1Click:Connect(function()

This errors is telling you that “UpdatesLog” is nil / doesn’t exist which means that its parent couldn’t find it. Maybe check the spelling here:

That gives me another error

Players.killersfatality.PlayerGui.MainMenuGUI.MainFrame.Buttons.UpdatesButton.UpdatesLogOPEN:8: attempt to index nil with Visible

Could you take a picture of the hierarchy of the GUIs? Like the parents and children in the explorer

image
UpdateLogsOPEN is the script i am scriptin

2 Likes

Okay it seems like you’re just referencing the UpdateLogFrame incorrectly. Try replacing this line:

With this line:

local openframe = mainframe:FindFirstChild(“UpdateLogFrame”)

I know this is unrelated but if I may ask, how did you get that programmer role?

1 Like

Developer Forum | Roblox or Programmers - Developer Forum | Roblox

1 Like

The reason the TextButton is registered as nil is because you have used FindFirstChild(), which is generally used when you are unsure that a child will exist.

In this case, since it is a client-side script, you need to replace FindFirstChild() with WaitForChild(), which will yield the code until the given child exists. WaitForChild() is very helpful within the client when a given object is needed for the code to run correctly.

Example:

local updatebutton = buttons:WaitForChild("UpdatesButton")
--this will make the script wait until the child exists. Make sure you
--put the correct name in character for character, otherwise you can get an infinite yield error where it is waiting forever.

Hope this helps!

1 Like

Ah yes this helped, I also changed a few things
@12345koip @Doomcolp
I did what you both said, there are no errors, but the frame doesn’t show up when i click the updates button

local sgui = startergui.MainMenuGUI
local mainframe = sgui:FindFirstChild("MainFrame")
local buttons = mainframe:FindFirstChild("Buttons")
local updatebutton = buttons:WaitForChild("UpdatesButton")
local openframe = mainframe:WaitForChild("UpdateLogFrame")

openframe.Visible = false

script.Parent.MouseButton1Click:Connect(function(click)
	openframe.Visible = true
end)

Try this:

updatesbutton.MouseButton1Click:Connect(function()
    openframe.Visible = true
end)

Your other code was using script.Parent, therefore making the variable unnecessary.

Yes, I tried that, that’s why I switched it to script.Parent

You are editing it in StarterGui, from the top variable. Change the sgui variable if it is set to the StarterGui.

local sgui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
1 Like

Nevermind, it works. Thanks my code is now

local sgui = startergui:WaitForChild("MainMenuGUI")
local mainframe = sgui.MainFrame
local buttons = mainframe:FindFirstChild("Buttons")
local updatebutton = buttons:FindFirstChild("UpdatesButton")
local openframe = mainframe.UpdateLogFrame

openframe.Visible = false

updatebutton.MouseButton1Click:Connect(function(click)
	openframe.Visible = true
end)
1 Like

For that variable, you are using FindFirstChild() again! Change it to WaitForChild().

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.