So I’m having trouble with storing strings, all of my values are stored in a table. Here’s the code:
local DataStore = game:GetService("DataStoreService")
local sentodata = DataStore:GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(player)
local data = Instance.new("Folder", player)
data.Name = "Data"
local toSave
local clan = Instance.new("IntValue", data)
local money = Instance.new("IntValue", data)
local speed = Instance.new("IntValue", data)
local strength = Instance.new("IntValue", data)
local endurance = Instance.new("IntValue", data)
local stamina = Instance.new("IntValue", data)
local hunger = Instance.new("IntValue", data)
local shakecam = Instance.new("BoolValue", data)
local lastname = Instance.new("StringValue", data)
local tier = Instance.new("StringValue", data)
local rpname = Instance.new("StringValue", data)
clan.Name = "ClanName"
money.Name = "Yen"
speed.Name = "Speed"
strength.Name = "Strength"
endurance.Name = "Endurance"
stamina.Name = "Stamina"
hunger.Name = "Hunger"
shakecam.Name = "ShakeCam"
lastname.Name = "LastName"
tier.Name = "Tier"
rpname.Name = "RPname"
local success, err = pcall(function()
toSave = sentodata:GetAsync(player.UserId)
end)
if success then
if type(toSave) == "table" then
clan.Value = toSave[1]
money.Value = toSave[2]
speed.Value = toSave[3]
strength.Value = toSave[4]
endurance.Value = toSave[5]
stamina.Value = toSave[6]
hunger.Value = toSave[7]
rpname.Value = toSave[8] -- Where the error occured
else
clan.Value = 1
money.Value = 0
speed.Value = 20
strength.Value = 0
endurance.Value = 0
stamina.Value = 10
hunger.Value = 1
rpname.Value = "Unnamed"
end
end
local toSaveData = {clan.Value, money.Value, speed.Value, strength.Value, endurance.Value, stamina.Value, hunger.Value, rpname.Value}
clan.Changed:Connect(function()
toSaveData[1] = clan.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
money.Changed:Connect(function()
toSaveData[2] = money.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
speed.Changed:Connect(function(n)
if strength.Value == 60 then
strength.Value = math.clamp(n, 0, 60) --MAXED VALUE
end
toSaveData[3] = speed.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
strength.Changed:Connect(function(n)
if strength.Value == 600 then
strength.Value = math.clamp(n, 0, 600)
end
toSaveData[4] = strength.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
endurance.Changed:Connect(function(n)
if strength.Value == 900 then
strength.Value = math.clamp(n, 0, 900)
end
toSaveData[5] = endurance.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
stamina.Changed:Connect(function(n)
if strength.Value == 2000 then
strength.Value = math.clamp(n, 0, 2000)
end
toSaveData[6] = stamina.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
hunger.Changed:Connect(function()
toSaveData[7] = hunger.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
rpname.Changed:Connect(function()
toSaveData[8] = rpname.Value
sentodata:SetAsync(player.UserId, toSaveData)
end)
game.Players.PlayerRemoving:Connect(function(player)
sentodata:SetAsync(player.UserId, toSaveData)
end)
end)
Here’s what the output looks like:
22:23:27.550 ServerScriptService.DataStores.Datastore:57: invalid argument #3 (string expected, got nil) - Server - Datastore:57