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](/secure-uploads/uploads/original/5X/f/7/4/6/f7463f27c8e889f43f65cfb82d2cb2eff273197a.png)
![image](/secure-uploads/uploads/original/5X/d/f/d/e/dfded0763df7b539bc6d40a8b58bf360a6a95988.png)
I have an issue where a button click is not being detected and there is no reason for it to not work please help!
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)
Thank you so much! The “Case 2” Helped!
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.