Hi guys! I been making a save script but then I got this error; 14:44:56.063 - ServerScriptService.SaveScript2:9: bad argument #3 to 'Value' (string expected, got nil)
This is the output: 14:44:56.063 - ServerScriptService.SaveScript2:9: bad argument #3 to 'Value' (string expected, got nil) 14:44:56.064 - Stack Begin 14:44:56.066 - Script 'ServerScriptService.SaveScript2', Line 9 14:44:56.067 - Stack End
So this is the error: 14:44:56.063 - ServerScriptService.SaveScript2:9: bad argument #3 to 'Value' (string expected, got nil)
I put the code inside a script and the script's parent is ServerScriptService, which means the script is inside the ServerScriptService, should I move it? Should I change anything?
This is the code inside the script;
local DataStore = game:GetService("DataStoreService"):GetDataStore("Slot1Taken") local DataStore2 = game:GetService("DataStoreService"):GetDataStore("CurrentImage") local DataStore3 = game:GetService("DataStoreService"):GetDataStore("NumberAmount") game.Players.PlayerAdded:connect(function(plr) local PlayerKey = "user_" .. plr.userId local slot1taken = plr:WaitForChild("Slot1Taken") slot1taken.Value = DataStore:GetAsync(PlayerKey) local slot1currentimage = plr.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage:WaitForChild("CurrentImage") slot1currentimage.Value = DataStore2:GetAsync(PlayerKey) local slot1amount = plr.PlayerGui.MenuGui.InventoryMain.InventoryFrame.InventoryBackground.ElementSlot1.ElementImage.Amount:WaitForChild("NumberAmount") slot1amount.Value = DataStore3:GetAsync(PlayerKey) end)
Tell me how to fix it and if you have time please debug it and change the script so it works, I need explaining, also tell me if I need to move anything or change anything. This is a save script to save stuff. Please help!
If you helped I thank you for helping me, if you tried to help thank you too, this is quite hard.
The reason it doesn't work is well PlayerKey is a value that doesnt exist "PlayerKey"Is a string value that does exist.Basically when ya use datatstore:GetASync you use string so
DataStore:GetASync("PlayerKey")
Here is a link to help you http://wiki.roblox.com/index.php?title=Saving_Player_Data
If this helped then please upvote and accept the answer
slot1taken.Value = DataStore:GetAsync(PlayerKey)
You are trying to get a player's data without first making sure that they have any data in the first place. Take a look at this example from Roblox.
local function setupPlayerData(player)
local data = playerData:GetAsync(player.UserId)
if not data then
data = {Money = 0, Experience = 0}
playerData:SetAsync(player.UserId, sessionData[player])
end
sessionData[player] = data
end
Notice how if not data then
covers for the potential error and then makes sure that there is set data with SetAsync here: data = {Money = 0, Experience = 0}
playerData:SetAsync(player.UserId, sessionData[player])