Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cant edit a textbox in a surface GUI?

So I'm wanting to edit a textbox in-game with a tool and for some reason it gets focus, but it doesn't let you type, anyone know why and how to fix this?

-local script inside a tool

local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function(mouse)print"equiped"
	mouse.Button1Down:Connect(function()
		if mouse.Target.Name == "Board" then
			game.ReplicatedStorage.Remotes.Write:FireServer(player) 
		end
	end)
end)

-script inside the model

local function write(player)
	local text = script.Parent.Board.SurfaceGui.TextBox
	text:CaptureFocus()
	text.Text = ""
	text.TextEditable = true
end
game.ReplicatedStorage.Remotes.Write.OnServerEvent:Connect(write)

1 answer

✓ Accepted answer

I believe the 2nd script you posted is in a server script, and CaptureFocus can only be used in a local script

I recommend just putting them together like this

local function write(player)
    local text = script.Parent.Board.SurfaceGui.TextBox
    text:CaptureFocus()
    text.Text = ""
    text.TextEditable = true
end

local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
script.Parent.Equipped:Connect(function(mouse)print"equiped"
    mouse.Button1Down:Connect(function()
        if mouse.Target.Name == "Board" then
            write()
        end
    end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.