Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unable to assign property Text. string expected, got nil (?)

Asked by 2 years ago
Edited 2 years ago

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)
0
GetAsync() will attempt to retrieve data. When you are saving something, you want to use SetAsync() or UpdateAsync() depending on the purpose. PhantomVisual 992 — 2y
0
Alright, but where should I place SetAsync() or UpdateAsync()? imnotaguest1121 362 — 2y

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
2 years ago

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.

Ad

Answer this question