Hello! I am trying to make a DataStore script for keybinds in my game. I have string values saved in a table. When I test the script, I get an error: Invalid argument #3 (string expected, got nil) It is on line 29 - 33.
local ds = game:GetService("DataStoreService")
local keys = ds:GetDataStore("KeySave")
game.Players.PlayerAdded:Connect(function(player)
local playerFolder = Instance.new("Folder", game.ReplicatedStorage)
playerFolder.Name = player.Name
local keybindFolder = Instance.new("Folder", playerFolder)
keybindFolder.Name = "Keybinds"
local stopKeyBind = Instance.new("StringValue", keybindFolder)
stopKeyBind.Name = "stopKeyBind"
local readyKeybind = Instance.new("StringValue", keybindFolder)
readyKeybind.Name = "readyKeyBind"
local lPunch = Instance.new("StringValue", keybindFolder)
lPunch.Name = "lPunchKeyBind"
local rPunch = Instance.new("StringValue", keybindFolder)
rPunch.Name = "rPunchKeyBind"
local fightingKeyBind = Instance.new("StringValue", keybindFolder)
fightingKeyBind.Name = "fightingPositionKeyBind"
local keyStats = keys:GetAsync(player.UserId)
if keyStats ~= nil then
stopKeyBind.Value = keyStats[1]
readyKeybind.Value = keyStats[2]
lPunch.Value = keyStats[3]
rPunch.Value = keyStats[4]
fightingKeyBind.Value = keyStats[5]
else
stopKeyBind.Value = "p"
readyKeybind.Value = "r"
lPunch.Value = "q"
rPunch.Value = "e"
fightingKeyBind.Value = "f"
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local save = {}
table.insert(save, game.ReplicatedStorage[player.Name].Keybinds.stopKeyBind.Value)
table.insert(save, game.ReplicatedStorage[player.Name].Keybinds.readyKeyBind)
table.insert(save, game.ReplicatedStorage[player.Name].Keybinds.lPunchKeyBind.Value)
table.insert(save, game.ReplicatedStorage[player.Name].Keybinds.rPunchKeyBind.Value)
table.insert(save, game.ReplicatedStorage[player.Name].Keybinds.fightingPositionKeyBind.Value)
keys:SetAsync(player.UserId,game:GetService("HttpService"):JSONEncode(save))
end)
Any help would be appreciated. Thanks!
