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
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
Fixed this by making another remote event and used :FireClient()