Guei not working!

hello so am making gui but is not working, here the code:

game stargertergui. mousebuttondown:Function(connect() 
     print(hello world!)
     print(code worked!)

thanks for helping meee!

1 Like

The proper code would be:

   print("Hello world!")
   print("Code worked!")

Breakdown, line one goes through player gui to find a button class
again on line one you did “function” “connect”, you cant function a connect, a function is a specific task that can be reused thus, what you would do is, connecting a function that runs everytime MouseButton1Down is fired.

Print statements need a string, or a variable ( could be number too ) in your case it needs to be a string, if its a variable please use no spaces.

EDIT: Thanks to @p49p0 to mentioning my mistake, everything in StarterGui replicates to the PlayerGui

local SG = script.Parent -- lazy to edit, pretend this is a starter gui lol
local Screen = SG:WaitForChild('ScreenGui')
local Button = Screen:WaitForChild('TextButton')
     print("congratulations, you farted on the button.")

do you even know gui displayed on players is in their PlayerGui folder

Couple things

  • You’re getting the StarterGui instead of the PlayerGui (Unless if you want to get it server sided)

  • You mixed up “function” & Connect

  • You have to encase the print statements in strings, otherwise you’re attempting to find global variables

1 Like

Yes sorry, should have been script.parent or player gui

1 Like

That would still theoretically work if it was in a local script (I think)

THANKS SO MUCH, am so new to programming :frowning:

1 Like
game.Players.LocalPlayer.PlayerGui.(Path to your gui button here (For example, ScreenGui.TextButton)).MouseButton1Down:Connect(function()
     print("hello world!")
     print("code worked!")
1 Like

this topic is my life of memes.
the spaces, the low caps in the code.