So, I am trying to make a test button, before I start doing what I am trying to do, once you click it it is supposed to send to the output “Button Pressed!” But it isnt.
Because you’re waiting for events in StarterGui which is only a placeholder for GUIs to be replicated to clients when they join. The GUIs player’s see are stored in their PlayerGui folder which is in their Player instance. Otherwise your code seems to work fine.
The Developer Hub website is linked here if you need to know more.
local MainGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MainGui")
This would be an example of what to replace with your current MainGui code.
local MainGui = game.Players.Localplayer.PlayerGui.MainGui
local Main = game.Players.Localplayer.PlayerGui.MainGui.Main
local Off = game.Players.Localplayer.PlayerGui.MainGui.Main.OffButton
Off.MouseButton1Click:Connect(function()
print (“Button Pressed!”)
end)
Yes, just make sure to include :WaitForChild("Child Name Here") since when it comes to stuff on the client it will take sometime for everything to load in perfectly and may lead to issues if your scripts load before your GUIs replicate.
Yes, but I like to make code that doesn’t depend on the location of the script. Since it’s inefficient to have a separate script for each button. Also, I just like to keep organized so trying to keep scripts in StarterPlayerScripts is what I do.