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

Why is my textbox.FocusLost not working? [Answered by me]

Asked by 3 years ago
Edited 3 years ago

Im making an instagram story question in roblox, and when the part the player answer the question, focus lost is bugging. I don't want to use any button I just want to use focuslost here's the script

game.Players.PlayerAdded:Connect(function(plr)
    game.ReplicatedStorage.askquestion.OnServerEvent:Connect(function(player,question)
        player.PlayerGui.ScreenGui.QNAANSWER.Visible = true
        player.PlayerGui.ScreenGui.QNAANSWER.Frame.TextLabel.Text = question
        print(player.PlayerGui.ScreenGui.QNAANSWER.Frame.TextLabel.Text)
        print(player.PlayerGui.ScreenGui.QNAANSWER.Frame.TextBox.Text)
        print(plr.Name)
        player.PlayerGui.ScreenGui.QNAANSWER.Frame.TextBox.FocusLost:Connect(function()
            print('ok')
        end)
        plr.PlayerGui.ScreenGui.QNAANSWER.Frame.TextBox.FocusLost:Connect(function()
            print('ok')
        end)
    end)
end)

as you might've guessed it's from a script not a local script, placed in the serverscriptservice no errors in output. This is how the explorer looks like

0
any help would be appreciated WINDOWS10XPRO 438 — 3y
0
woah still no answer? damn WINDOWS10XPRO 438 — 3y
0
i'll try putting the script at a local script WINDOWS10XPRO 438 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

why are you handling guis on the server, you shouldn't handle guis on the server, also there is no need for playerAdded event, just get a question using a remote function from the client to the server, for example

-- Server
local questions = {{questionText = "What is 1 + 1", answer = 2}, {questionText = "Never gonna?", answer = "give you up"}} -- I don't use instagram so I don't know what the story question system is

local function createQuestion(text, answer)
    local newQuestion = {}
    newQuestion.questionText = text or ""
    newQuestion.answer = answer
    local index = questions[#questions+1]
    questions[index] = newQuestion
    return index
end

local function getQuestion(index)
    return questions[index]
end

local function getRandomQuestion()
    local rand = Random.new(os.time())
    local question = questions[rand:NextInteger(1, #questions)]
    return question 
end

game.ReplicatedStorage.GetQuestion.OnServerInvoke = function(player)
    local question = getRandomQuestion() -- Ask a random question or whatever, you can even send the same question e.g return questions[1]
    return question
end)

-- Client
-- Instead of firing askquestion event
local question = game.ReplicatedStorage.GetQuestion:InvokeServer()

if (question) then
    local questionGui = player.PlayerGui:WaitForChild("ScreenGui") -- "player" should be "game.Players.LocalPlayer"
    local qnaAnswer = questionGui:WaitForChild("QNAANSWER")

        qnaAnswer.Visible = true
        qnaAnswer.Frame.TextLabel.Text = question.questionText
        print(qnaAnswer.Frame.TextLabel.Text)
        print(qnaAnswer.Frame.TextBox.Text)
        print(plr.Name)

    qnaAnswer.Frame.TextBox.FocusLost:Connect(function(hasPressedEnter)
            -- Check whatever
        end)
        plr.PlayerGui.ScreenGui.QNAANSWER.Frame.TextBox.FocusLost:Connect(function(pressedEnter)
             -- code here
        end)
end
0
didn't you see the fire server? WINDOWS10XPRO 438 — 3y
0
btw we're alike i also dont use instagram xD WINDOWS10XPRO 438 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Fixed this by making another remote event and used :FireClient()

Answer this question