Hey all, I’ve been trying to fix this for 2 days now, so I thought I’d try my luck here. I have a surface gui inside of a tool, and the inputs refuse to register at all. I’ve looked it up on the devforum and tried:
Setting the gui’s ToolPunchThroughDistance to 1000
Parenting the gui to PlayerGui and setting the adornee to the part
Parenting the part holding the gui to workspace
And none of these have worked. For reference, here’s how the tool & gui are setup:
And here are the relevant pieces of code that deal with the gui:
PDAClient (the tool localscript)
-- Services
local Players = game:GetService("Players")
-- Player vars
local player = Players.LocalPlayer
local playerGui = player.PlayerGui
-- Tool vars
local tool = script.Parent
local handle = tool:WaitForChild("PDA")
-- GUi vars
local screen = handle.Screen
local gui = screen.SurfaceGui
-- Tool funcs
local function equipped()
screen.Parent = workspace
gui.Parent = playerGui
gui.Adornee = screen
end
local function unEquipped()
screen.Parent = handle
gui.Parent = screen
end
PDAGui (the gui localscript)
-- GUI vars
local gui = script.Parent
local beepSound = gui:WaitForChild("BeepSound")
local container1 = gui.Container
local container2 = container1.Container
local buttons = container2.Buttons
local menus = container2.Menus
-- Gui funcs
for _, button in buttons:GetChildren() do
if button:IsA("TextButton") then
print("meep")
button.MouseButton1Down:Connect(function()
print("click!")
beepSound:Play()
for _, menu in menus:GetChildren() do
if menu.Name ~= button.Name then
menu.Visible = false
else
menu.Visible = true
end
end
end)
end
end
Are the print statements working at all? no outputs?
If the buttons are not detecting the click then I recommend you to read this Solution for mousebutton1click not detecting. It could be an overlaps between UI elements which are blocking the click detection. To know if that’s the case try to remove everything other than the buttons on a brand new set up and see if it works, if it does then you might have to make a new set up or change you ZIndex of the buttons maybe.
From my knowledge, click detectors can’t be used if the player has a tool equipped, so the issue might be from the tool itself, but I’m not really sure
print("meep") works, but not print("click!")
I tried what you said and reduced the surfacegui to just the buttons, but it still doesn’t register inputs, only printing “meep”.
-- GUI vars
local gui = script.Parent
local beepSound = gui:WaitForChild("BeepSound")
-- Gui funcs
for _, button in gui:GetChildren() do
if button:IsA("TextButton") then
print("meep")
button.Activated:Connect(function()
print("click!")
beepSound:Play()
end)
end
end
If this may be what’s causing this problem, I recommend assigning the tabs to keypresses (preferably keys that are physically next to eachother on the keyboard for ease)
Then have a look at this one : Local script doesn’t work in workspace. Maybe you have to make sure it’s a script then a local one. I mean the gui will be visible to other players too right? And it will be inside of workspace when the tool is activated. Try using a script. Yet I am not sure this will work since I never used a script for a gui.
local ui = script.Parent.SurfaceGui
local handle = script.Parent.Handle
script.Parent.Equipped:Connect(function()
ui.Parent = game.Players.LocalPlayer.PlayerGui
ui.Adornee = handle
end)
script.Parent.Unequipped:Connect(function()
ui.Parent = script.Parent
end)
for i,v in ipairs(ui.Frame:GetChildren()) do
if v:IsA("TextButton") then
v.Activated:Connect(function()
print("pressed" .. v.Text)
end)
end
end
I think you need to parent the SurfaceGui to StarterGui and set the SurfaceGui’s “Adornee” property to the original parent (“Screen”), since BillboardGuis also have this issue.
Edit: Oops, I forgot the part where you mentioned this exact thing.
Maybe check if something inside the tool is blocking the mouse’s hit cast? Hitboxes could be off sometimes. How about isolating the GUI’s parent temporarily in a new tool and see if it works?
Everything relevant is properly active, but I noticed you kept the GUI code in the tool localscript as well, and once I tried that, it actually worked! Also, thanks to Frosty’s suggestion of checking if parts were blocking the screen, I realized I left the CanQuery property on the screen off, preventing any click detection at all.
So to summarize for anyone experiencing this problem:
Make sure your screen is clickable (CanQuery is on and it’s not being blocked by parts)
Parent the gui to PlayerGui and set the adornee to the screen