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.
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.
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
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.
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’