Button click not being detected

I have an issue where a button click is not being detected and there is no reason for it to not work please help!


image
image

1 Like

The UI that is inside of StarterGui is not the same instance that you see on your screen. The one you see on your screen is a clone of the one in StarterGui. There’s 2 ways you can fix this:

Case 1 – You can define the GUI as script.Parent – assuming that it is the LocalScript directly under the Pannel instance.

local GUI = script.Parent
GUI.Holder.PenaltyFrame:WaitForChild("ServeBtn").MouseButton1Click:Connect(function()
    -- Rest of code
end)

Case 2 – You can get the GUI through the PlayerGui instance that is inside of the Player. Use this if this is the LocalScript parented to PenaltyFrame, as it looks a lot cleaner compared to defining GUI as script.Parent.Parent.Parent :

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local GUI = PlayerGui:WaitForChild("Pannel")

GUI.Holder.PenaltyFrame:WaitForChild("ServeBtn").MouseButton1Click:Connect(function()
    -- Rest of code
end)
2 Likes

Thank you so much! The “Case 2” Helped!

1 Like

In this case, because you have the Local Script inside of the ScreenGui object itself, it’s fine to just use “Script.Parent”, as @ProgrammingRottie mentioned in Case 1.

It’s pretty unnecessary to get the Player, then their PlayerGui, then the ScreenGui, because of what I said above and also because it’s just messy and really unnecessary.

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