Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Cesire 45
9 years ago

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)
0
Forgot to mention that the LocalScript is a child of the TextBox Cesire 45 — 9y
0
Are you trying to use a SurfaceGui or a BillBoardGui? M39a9am3R 3210 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

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
0
Um no it didn't print anything! Cesire 45 — 9y
0
Well both of the scripts you've given me doesn't work is this a studio related glitch? Cesire 45 — 9y
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.... KingLoneCat 2642 — 9y
0
ok It's under a surfaceGui sorry for the long response, being busy lately Cesire 45 — 9y
View all comments (3 more)
0
So did you figure it out? KingLoneCat 2642 — 9y
0
No I think I need to use Adornee which idk how to use. Cesire 45 — 9y
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 KingLoneCat 2642 — 9y
Ad
Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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)
0
Sadly that didn't work Cesire 45 — 9y
0
It works, I tested it. Perci1 4988 — 9y
0
hm weird Cesire 45 — 9y
0
what exactly isn't working about it? Perci1 4988 — 9y
Log in to vote
0
Answered by
Cesire 45
8 years ago

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)

Answer this question