Hello! I am working on a simple DataStorage that saves the text the player put Inside of a textbox and loads It. The problem Is that when you are trying to load the data (Aka the textbox text) an error appears saying:
Unable to assign property Text. string expected, got nil
Slot script:
local slot = script.Parent
local LoadButton = slot.LoadButton
local SaveButton = slot.SaveButton
local LoadFunction = game.ReplicatedStorage:WaitForChild("LoadSlot")
local SaveEvent = game.ReplicatedStorage:WaitForChild("SaveSlot")
local Textbox = game.Players.LocalPlayer.PlayerGui:WaitForChild("TrollStorage").TextBox
SaveButton.MouseButton1Click:Connect(function()
SaveEvent:FireServer(slot.Name, Textbox.Text)
end)
LoadButton.MouseButton1Click:Connect(function()
local data = LoadFunction:InvokeServer(slot.Name)
Textbox.Text = data
end)
ServerScriptService:
local SaveSlot = game:GetService("ReplicatedStorage").SaveSlot
local LoadSlot = game:GetService("ReplicatedStorage").LoadSlot
local Datastore = game:GetService("DataStoreService")
local slotStore = Datastore:GetDataStore("SlotStore")
function LoadSlot.OnServerInvoke(player, slot)
return slotStore:GetAsync(player.Name.."-"..slot)
end
SaveSlot.OnServerEvent:Connect(function(player, slot, data)
local Success = false
while not Success do
Success = pcall(function()
slotStore:GetAsync(player.Name.."-"..slot, data)
end)
end
end)

2 comments
GetAsync() will attempt to retrieve data. When you are saving something, you want to use SetAsync() or UpdateAsync() depending on the purpose.
Alright, but where should I place SetAsync() or UpdateAsync()?