Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you fix bad argument #3 to 'Value' (string expected, got nil) with saving?

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.

1 comment

0

Formatting

2 answers

✓ Accepted answer

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

2 comments

0

He does use a string. "local PlayerKey = "user_" .. plr.userId"

0

If you weren't as stupid ,you'd realise the problem is that he used a string and he shouldn't have.

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])

1 comment

0

You should use the Lua code block instead of Inline code

This discussion is preserved as it was. New answers, comments, and votes are closed.