Need help with script not working

Hello,

I have been having a problem where when I try and play my quiz game the buttons don’t work and the script automatically plays even though it hasn’t been activated. Here are some pictures, sorry if what is above is vague I’ll explain more below.


Here I am trying to make it so when the textbutton is clicked, it commits the string of code here. However it automatically does these things once I join the game and not when I’ve hit the button. The same goes for the picture below.

If you can tell me what I did wrong that would be very helpful, thanks!

You cant access the gui from StarterGui like this.
Plus, in the first photo, the if statement is useless. Just connect the function when the player clicks on that button.

Try to access that gui like this: script.Parent

Use this codings instead:

local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local PlayerGUI = LPlayer:WaitForChild("PlayerGui")
local GUI = PlayerGUI:WaitForChild("Test")

GUI.Frame.No.MouseButton1Click:Connect(function()
game.Workspace["Taco bell sound effect (bass boost)"].Playing = true
GUI.Visible = false
GUI.Notcool.Transparency = 0.15
LPlayer:Kick("You suck")
end)
local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local PlayerGUI = LPlayer:WaitForChild("PlayerGui")
local GUI = PlayerGUI:WaitForChild("Test")

GUI.Frame.Yes.MouseButton1Click:Connect(function()
GUI.Cool.Visible = true
game.Workspace["Getting Hard Hit Em Trap (30 sec)"].Playing = true
GUI.Visible = false
end)
1 Like

This is not how the :Connect() function works. The :Connect() function dosn’t return a true or false; instead, it attaches a function to be called every time the event happens. (In this case the event is MouseButton1Click). In order for your code to work you have to make a function first and then pass that function as a parameter to the :Connect() function. Here’s an example.

local function MyButtonCallback()
     print("The button was pressed!")
end

GuiButton:Connect(MyButtonCallback)

My bad, I had it like that originally and it still didn’t work.

Thanks! I’ll try it and see if it works!
Edit: It works! Thanks a lot!

So I have another problem. I’m using the exact code, nothing changed, but the no button isn’t working.

robloxapp-20220819-1011156.wmv (333.6 KB)

Video of what I was talking about. Sorry if it’s like totally random lol.

What error does it show in the output when you click it?

@CryoPlaysAlot