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

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

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

3 comments

0

any help would be appreciated

0

woah still no answer? damn

0

i'll try putting the script at a local script

2 answers

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

2 comments

0

didn't you see the fire server?

0

btw we're alike i also dont use instagram xD

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

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