How Do You Save the Input from a Textbox to a Replicated storage Value?

I’ve tried a few tutorial regarding the matter, but they all return the value as “nil.” I’m assuming that there is an error with this code, but I can’t locate any clearer tutorials on how to properly use a fireserver correctly in this specific instance. Any help or tutorials would be appreciated.

Local Script:

local Textbox = script.Parent.Parent.Parent.Parent.Parent.Story.TextBox
local ConfirmName = script.Parent.Parent.Parent.Parent.Parent.Story.ConfirmName 
local nameinput = script.Parent.Parent.Parent.Parent.Parent.Story.nameinput 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changeNameEvent = ReplicatedStorage:WaitForChild("ChangeNameEvent")

nameinput.FocusLost:Connect(function()
	print(nameinput.Text)
end)

ConfirmName.MouseButton1Up:Connect(function()
		local name = nameinput.Text
		changeNameEvent:FireServer(name)
		print(name)
end)

Regular Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changeNameEvent = Instance.new("RemoteEvent")
changeNameEvent.Name = "ChangeNameEvent"
changeNameEvent.Parent = ReplicatedStorage
local PlayerStats = ReplicatedStorage:WaitForChild("PlayerStats")

changeNameEvent.OnServerEvent:Connect(function(player, newName)
	PlayerStats.Name = newName
end)

If there are any better methods of doing this, that would be great to know as well.

Maybe in the FocusLost event you can fire the remoteevent then. Also, what specifically is returning nil?

1 Like

Unfortunately this did not work. But thank you for the suggestion. The part returning “nil” is the value of the variable within the replicated storage. If it is not returned as “nil”, then it sometimes returns as just “Playerstats” instead.

The local script returning the input just fine, however.

changeNameEvent.OnServerEvent:Connect(function(player, newName)
	PlayerStats.Name = newName
end)

Are you sure you wanted to set the name of PlayerStats to the new name, or the value of PlayerStats to the new name? If so, change it to PlayerStats.Value = newName

1 Like

Playersts is just a folder that the “name” variable is located within. The “name” variable is a string that I would like to hold the value of the player input from the textbox.

Is it a StringValue literally called “Name”?

1 Like

Yes. I was trying to keep it simple while I figured out how to make it work. I can change it if that would help.

Oh, the script must be confusing your use of the word Name. It’s changing the name of the folder, not the actual Name StringValue you have inside of it.

Try this:
PlayerStats["Name"].Value = newName

This tells the script you’re referring to the StringValue inside called ‘Name’

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.