You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Trying to save whatever input a player puts in a textbox and save it so that it is still there on their next playsession using SetAsync and GetAsync
- What is the issue? Include screenshots / videos if possible!
The local script recieves nil when I try to pass the data through a RemoteFunction, while it works on the server script and I can print the string and it saves just fine there.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Have tried browsing the devforum and rewatching videos on Datastoring to no avail due to my issue being quite specific.
Code in Local Script:
local Player = game.Players.LocalPlayer
local TextBox = Player.PlayerGui.ScreenGui.TextBox
local Remote = game.ReplicatedStorage.RemoteFunction
TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
local Text = TextBox.Text
Remote:InvokeServer(Text)
end
end)
Remote.OnClientInvoke = function(Player,TheThing)
print(TheThing)
end
Code in Server Script:
local Remote = game.ReplicatedStorage.RemoteFunction
local DSS = game:GetService("DataStoreService")
local SavedText = DSS:GetDataStore("SavedText")
Remote.OnServerInvoke = function(Player,Text)
local UserID = Player.UserId
local success, errormessage = pcall(function()
SavedText:SetAsync(UserID.."Text",Text)
end)
if success then
print("Saved")
end
end
game.Players.PlayerAdded:Connect(function(Player)
local UserID = Player.UserId
local Text
local success, Error = pcall(function()
TheThing = SavedText:GetAsync(UserID.."Text")
return TheThing
end)
if success then
print(TheThing)
Remote:InvokeClient(Player,TheThing)
end
end)