Is there a possible way to check to see if a textbutton has lost focus on mobile? I know it is possible on anything with a keyboard but how would I be able to do this on mobile devices?
TextButton.FocusLost
fires when focus is lost.
Fires for both pc and mobile. (You could also use .Focused
similarly)
TextButton.FocusLost:Connect(function()
--Do stuff
end)
TextBox.FocusLost should already cover this for you. If for whatever reason you’ve tried using FocusLost (not indicated in the OP what you’re currently doing) and it doesn’t fire for touch devices, then go to UserInputService.TextBoxFocusReleased.
None of these work at all, for some reason.
They all work perfectly fine, Mind sharing the code you used to utilize that event for further help?
.FocusLost
worked perfectly on my phone. You are doing something wrong.
Please share the code you find to “Not work”
local player = game:GetService("Players").LocalPlayer
script.Parent.TextBox.FocusLost:connect(function(enterPressed)
if enterPressed then
local count = 0
local plr
for i, v in next, game.Players:GetChildren() do
if string.len(v.Name) >= string.len(script.Parent.TextBox.Text) and string.lower(script.Parent.TextBox.Text) == string.lower(string.sub(v.Name, 0, string.len(script.Parent.TextBox.Text))) then
count = count + 1
plr = v
end
end
if not game:GetService("RunService"):IsStudio() and player.Name == plr.Name then
return
end
if count == 1 then
local item
for i, v in next, player.Character:GetChildren() do
if v.ClassName == "Tool" then
item = v
end
end
if item ~= nil then
script.Parent.RemoteEvent:FireServer(player,plr,item)
print("sent to server")
end
script.Parent.TextBox.Text = "Give"
end
end
end)
Just to get everything straight, Since you’re checking for the enterPressed Event you have to press Enter for it to work. (pretty obvious but just making sure)
If it still doesn’t work with you doing that then its not the FocusLost
event that is “broken”, Have you encountered any errors? If so please post them.
Make sure you press enter, otherwise this will not work. Also, try this. It should print false or true depending on if you press enter. I believe the problem is you did not press return, or your code is the problem.
local player = game:GetService("Players").LocalPlayer
script.Parent.TextBox.FocusLost:connect(function(enterPressed)
print(enterPressed)
if enterPressed then
local count = 0
local plr
for i, v in next, game.Players:GetChildren() do
if string.len(v.Name) >= string.len(script.Parent.TextBox.Text) and string.lower(script.Parent.TextBox.Text) == string.lower(string.sub(v.Name, 0, string.len(script.Parent.TextBox.Text))) then
count = count + 1
plr = v
end
end
if not game:GetService("RunService"):IsStudio() and player.Name == plr.Name then
return
end
if count == 1 then
local item
for i, v in next, player.Character:GetChildren() do
if v.ClassName == "Tool" then
item = v
end
end
if item ~= nil then
script.Parent.RemoteEvent:FireServer(player,plr,item)
print("sent to server")
end
script.Parent.TextBox.Text = "Give"
end
end
end)
So when I do it now, it prints “True”.
It does not fire the event.
That means it has to do with your code, Not the FocusLost
Event. I am pretty sure it doesn’t fire because it Returns if not game:GetService("RunService"):IsStudio() and player.Name == plr.Name then return end
And since you’re the only person testing (That’s what am guessing) The Statement player.Name == plr.Name
(that is if you’re testing without being in studio if you are that will end the script too) returns true therefore ends the script.
Oml, thank you so much. I am soo dumb.