I have created a story game
and i have create textbox to answer the question
but when i try to get text from textbox, the text do not change like player
in the video above will show you i have answer correctly answer but the script said it wrong
this is my script
local plrcorrect = {}
for i,v in pairs(game.Players:GetPlayers()) do
local answer
local file1 = v.QUESTION1
local file2 = v.QUESTION2
local plrtype = v.typeplr
if plrtype.Value == 1 then
answer =file1.Value + file2.Value
end
if plrtype.Value == 2 then
answer = file1.Value * file2.Value
end
local gui = v.PlayerGui.Question
print("plr "..gui.Frame.TextBox.Text)
if tostring(gui.Frame.TextBox.Text) == tostring(answer) then
table.insert(plrcorrect,v.Name)
gui.Frame.question.Text ="You answer correctly!"
else
gui.Frame.question.Text = "You answer wrong! The correct answer is "..tostring(answer)
end
wait(2)
gui.Frame:TweenPosition(UDim2.new(0.5,0,-1.6,0),nil,Enum.EasingStyle.Elastic,10)
end
if isEmpty(plrcorrect) then
CreateDialogueEvent:FireAllClients(teacherGalaxy_Image,table.concat(plrcorrect, ", ").." answer correctly!")
else
CreateDialogueEvent:FireAllClients(teacherGalaxy_Image,"All of student answer wrong!")
end
i have add print to print value in textbox but i got: Answer your question inside this box!
It same like old value that already have in textbox, watch video
Any text added to a textbox is kept on the client side and if you want the server to get the information you need to use RemoteEvents to send the data to the server. Just make sure you use Chat:FilterStringForBroadcast (If the message is going to everyone in the server) or Chat:FilterStringAsync (If the message is directed towards one player).
If you don’t allow the roblox filter to check over user submitted text your game will be subjected to moderation action so make sure you do that second step.
Any changes in the client won’t replicate to the server, this goes for GUIs as well. You can make it when the player has finished typing (by pressing enter), fire a remote event to the server then check if the answer is correct, etc.
-- Server side --
game.ReplicatedStorage.Mission1:FireAllClients(gui)
game.ReplicatedStorage.Mission1.OnServerEvent:Connect(function(plr,text)
plr.PlayerGui.Question1.Frame.TextBox.Text = text
end)
----------------
-- Client side --
game.ReplicatedStorage.Mission1.OnClientEvent:Connect(function(gui)
gui.Changed:Connect(function()
game.ReplicatedStorage.Mission1:FireServer()
end)
end)
Like this?
This is all script about it
for i,v in pairs(game.Players:GetPlayers()) do
local gui = game.ReplicatedStorage.Question:Clone()
gui.Parent = v.PlayerGui
gui.Frame:TweenPosition(UDim2.new(0.5,0,0.6,0),nil,Enum.EasingStyle.Elastic,10)
local question = math.random(1,1000)
local question2 = math.random(1,1000)
local typeo = math.random(1,2)
if typeo == 1 then
gui.Frame.question.Text = question.." + "..question2.." = ?"
print(question + question2)
end
if typeo ==2 then
print(question * question2)
gui.Frame.question.Text = question.." x "..question2.." = ?"
end
local questionvalue = Instance.new("NumberValue",v)
questionvalue.Name = "QUESTION1"
questionvalue.Value = question
local questionvalue2 = Instance.new("NumberValue",v)
questionvalue2.Name = "QUESTION2"
questionvalue2.Value = question2
local typeplr = Instance.new("NumberValue",v)
typeplr.Name = "typeplr"
typeplr.Value = typeo
end
game.ReplicatedStorage.TimerEvent:FireAllClients(30)
wait(31)
local plrcorrect = {}
for i,v in pairs(game.Players:GetPlayers()) do
local answer
local file1 = v.QUESTION1
local file2 = v.QUESTION2
local plrtype = v.typeplr
if plrtype.Value == 1 then
answer =file1.Value + file2.Value
end
if plrtype.Value == 2 then
answer = file1.Value * file2.Value
end
local gui = v.PlayerGui.Question
print("plr "..gui.Frame.TextBox.Text)
if tostring(gui.Frame.TextBox.Text) == tostring(answer) then
table.insert(plrcorrect,v.Name)
gui.Frame.question.Text ="You answer correctly!"
else
gui.Frame.question.Text = "You answer wrong! The correct answer is "..tostring(answer)
end
wait(2)
gui.Frame:TweenPosition(UDim2.new(0.5,0,-1.6,0),nil,Enum.EasingStyle.Elastic,10)
end
if isEmpty(plrcorrect) then
CreateDialogueEvent:FireAllClients(teacherGalaxy_Image,table.concat(plrcorrect, ", ").." answer correctly!",TGalaxy)
wait(10)
for i=1, #plrcorrect do
if i==1 then
CreateDialogueEvent:FireAllClients(teacherGalaxy_Image,"YAY!",plrcorrect[i])
end
end
else
getRandomPlayer()
CreateDialogueEvent:FireAllClients(RandomPlayerImage(),"Nooooo my cookies",randomPlayerName)
CreateDialogueEvent:FireAllClients(teacherGalaxy_Image,"All of student answer wrong!")
end
wait(10)