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)
On your ServerScriptService
script, instead of doing
slotStore:GetAsync(player.Name.."-"..slot, data)
on line 15, consider doing this:
slotStore:SetAsync(player.Name.."-"..slot, data)
Just like @PhantomVisual said in the comments, GetAsync
is used to "get" or "load" data, and SetAsync
will be "set" or "save" data.