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

How do I make a TextBox CaptureFocus() when i click on it?

I wanna use MouseButton1Down so how do i do it?

This is what i've tried in a LocalScript but it didn't work:

local Mouse = game.Players.LocalPlayer:GetMouse()
 
Mouse.MouseButton1Down:connect(function(Key)
		script.Parent:CaptureFocus()
end)

2 comments

0

Forgot to mention that the LocalScript is a child of the TextBox

0

Are you trying to use a SurfaceGui or a BillBoardGui?

3 answers

✓ Accepted answer

Ok, so there answer above has no problem in it just that he didn't add the :Capture Focus Function in there.... So just do this following code inside of a Local Scriptunder the TextBox...

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function()
script.Parent:CaptureFocus()
end

7 comments

0

Um no it didn't print anything!

0

Well both of the scripts you've given me doesn't work is this a studio related glitch?

0

I think it's your studio because my script should work -_- I just now checked it and make sure your TextBox is under a ScreenGui or SurfaceGui please....

0

ok It's under a surfaceGui sorry for the long response, being busy lately

0

So did you figure it out?

0

No I think I need to use Adornee which idk how to use.

0

It's easy to use... You can do..... game.Workspace.Gui.Adornee = game.Workspace.Baseplate This means that the Gui will be on the baseplate

MouseButton1Down is an event of GUIs. This means you can only use it on TextButtons and ImageButtons (with the event firing when the gui is clicked).

mouse has a separate event, which is just Button1Down. You can use that.

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:connect(function()
	print("clicked")
end)

4 comments

0

Sadly that didn't work

0

It works, I tested it.

0

hm weird

0

what exactly isn't working about it?

Ok I got it to work, you never told me the localscript had to be in StarterGui LOL :D


--Adornee is set to "Test" a part in game.Workspace


local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:connect(function()
	if mouse.Target == "Test" then
	script.Parent:CaptureFocus()
	end	
end)

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