SurfaceGui buttons only working when changing window

So basically, I’ve made this 3D GUI menu using a part with a SurfaceGui on it and moving it in front of the camera. However, the buttons seem to be inactive (not clickable) until I switch the studio tab to a script and then switch back to the main tab.

No, it’s not a CanQuery issue, nor a SurfaceGui not in the StarterGui, nor a CanTouch problem, nor an object blocking the camera, because as I mentioned, it works perfectly fine after changing the tab. But obviously, I want it to work consistently, as this error replicates in-game as well.

I think this might be an engine issue, but I want to know beforehand if anyone else has encountered this problem and knows how to fix it.

Not sure but have you set the Adornee?

This, and make sure that all of said buttons have their Active property set to true

As i have said above, its not an issue of the surface gui not being an adornee, cos it works perfectly fine and detect any mouse interaction when switching tabs.

For some reason it wont work when pressing the play button but as soon as i change the tab to a script and back to the game tab they will start working again.

Could you show me the script that is handling everything?

That doesnt 100% mean its not the problem, you have no idea how weird roblox is, so might as well, cause to my experience, surface GUIS never worked until I set the adronee, so might as well try it right?

1 Like

Yes i can but im pretty sure the script has nothing to do with this issue…

local Knit = require(game:GetService("ReplicatedStorage").Packages.Knit)
local Config = require(game:GetService("ReplicatedStorage").Shared.Config)

local Assets = game:GetService("ReplicatedStorage").Assets

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Gui = Player:WaitForChild("PlayerGui")

-- Controller
local MenuController = Knit.CreateController({
	Name = "MenuController"
})

MenuController.Camera = game.Workspace:WaitForChild("MainSceneCam")
MenuController.Clickable = true
MenuController.Funcs = {}

function MenuController:InsertFunction(But : TextButton)
	But.MouseButton1Click:Connect(function()
		print("Elpepemoc")
	end)
end

function MenuController:KnitStart()
	print("[MenuController] Inniting...")
	
	local Frame : Part = Instance.new("Part", game.Workspace)
	Frame.Name = "MainMenu3DContainer"
	Frame.CanCollide = false
	Frame.CanQuery = true
	Frame.CanTouch = false
	Frame.Massless = true
	Frame.CastShadow = false
	Frame.Transparency = 1
	Frame.Size = Vector3.new(5, 10, 10)
	--Frame.CollisionGroup = "3DGuis"
	
	-- Gui
	local SGui : SurfaceGui = Player.PlayerGui:WaitForChild("MainMenuGui")
	SGui.Adornee = Frame
	SGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	
	local ppX = SGui.CanvasSize.X / Frame.Size.X
	local ppY = SGui.CanvasSize.Y / Frame.Size.Y
	
	SGui.PixelsPerStud = (ppX + ppY)/2
	print( (ppX + ppY)/2)
	
	-- Buttons
	for i, v in ipairs(SGui.Container.ButtonContainer:GetDescendants()) do
		if v:IsA("TextButton") then
			self:InsertFunction(v)
		end
	end
	
	-- Maths
	
	game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
		local Camera : Camera = game.Workspace.Camera
		
		local xR = Camera.ViewportSize.X/Camera.ViewportSize.Y
		local yR = Camera.ViewportSize.Y/Camera.ViewportSize.X

		local offset = Vector3.new(-3, -2.25, 9)
		local CalculatedOffset = Vector3.new(offset.X * xR, offset.Y * yR, -offset.Z)

		local rotOffset = Vector3.new(0, 45, 0)
		local calculatedRot = CFrame.Angles(math.rad(rotOffset.X), math.rad(rotOffset.Y), math.rad(rotOffset.Z))
		
		local newCFrame = Camera.CFrame * CFrame.new(CalculatedOffset) * calculatedRot
	
		TweenService:Create(Frame, TweenInfo.new(1/100), {CFrame = newCFrame}):Play()
		--Frame.CFrame = newCFrame
		
	end)
end

return MenuController

And yes, ive tried making the script a local script instead of a module within the knit framework.

Ur not getting it, its already set as the adornee and everything works out. Im starting to believe this might be an engine issue.

oh I never saw you state the fact that you set it.
Is it possible you could provide a bear-bones version of it so we could test on it? Cause this is some weird behavior.

Try testing it in Roblox. get the link and join the game

As i said in the first message “this error replicates in-game as well.”

Yeah sure! Sorry for late replying i wasnt at home.
bear-bones3dmenu.rbxl (199.0 KB)

Here u have a bear-bone version of it, same script same everything. Still doesnt works correctly for me, its not until i change the tab that the buttons are clickable.

In game it replicates and it even gets weirder.

I guess ill just have to go with a normal ui until roblox fixes surfaceguis…

1 Like

On the rare case I am able to click it, it seems to be working, so it may be an engine bug.

Yeah hard to tell with whatever this is

1 Like

About the gui just randomly moving… Yeah ignore it, its already fixed on the main game.

But yeah it really seems to be an engine bug so ill just use a normal 2d GUI. Ty for ur time, really appreciate it.

1 Like

Yw! it sucks that this happens, the UI looked so cool lol

1 Like

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