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

How can I transfer a Textbox's Text from the Client to the Server?

Asked by 1 year ago

So, I have been working on a game that involves a TextBox and a TextButton. What I want to happen is, when a player types in the TextBox, then clicks the Confirm Button, it will send the Text in the TextBox to the Server using RemoteEvents.

Then, a Server Script will make a new StringValue that has the TexBox's Text as its Value.

I have tried testing it out, and every time I do, it makes the StringValue's Value Blank on the Client and Server.

(The RemoteEvent name is called "NewStringEvent")

Here is the LocalScript for the Confirm Button:

local TextBox = script.Parent.Parent.TextBox.Text

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("NewStringEvent")

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
    script.Parent.Parent.Parent.SuccessFrame.Visible = true

    RemoteEvent:FireServer(TextBox)
end)

Here is the Server Script for the RemoteEvent:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local NewStringEvent = ReplicatedStorage.NewStringEvent

local counter = 0

NewStringEvent.OnServerEvent:Connect(function(player, TextBox)
    counter += 1
    local newString = Instance.new("StringValue")
    newString.Name = player.Name .. "s_" .. counter .. "_Text"
    newString.Value = TextBox
    newString.Parent = ReplicatedStorage:WaitForChild(player.Name .. "s_Texts")
end)

Any Help On This?

1 answer

Log in to vote
1
Answered by 1 year ago

The only issue I can spot is that you are getting the text outside the event. Putting it outside the event means the variable will not update; it will remain the same from when the script loads.

Update the variable by putting it inside the event.

local TextBox = script.Parent.Parent.TextBox

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("NewStringEvent")

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
    script.Parent.Parent.Parent.SuccessFrame.Visible = true

    local Text = TextBox.Text
    RemoteEvent:FireServer(Text)
end)
0
Thank you so much! It works. JackyW9cky 27 — 1y
Ad

Answer this question