I want to store player’s data from a table. Here’s the code:
local DataStore = game:GetService("DataStoreService")
local sentodata = DataStore:GetDataStore("Sento")
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)
clan.Name = "ClanName"
money.Name = "Yen"
speed.Name = "Speed"
strength.Name = "Strength"
endurance.Name = "Endurance"
stamina.Name = "Stamina"
hunger.Name = "Hunger"
local success, err = pcall(function()
toSave = sentodata:GetAsync(player.UserId)
end)
if success then
if type(toSave) ~= "table" then
clan.Value = toSave[1] --Where the error occurred
money.Value = toSave[2]
speed.Value = toSave[3]
strength.Value = toSave[4]
endurance.Value = toSave[5]
stamina.Value = toSave[6]
hunger.Value = toSave[7]
else
clan.Value = 1
money.Value = 0
speed.Value = 16
strength.Value = 0
endurance.Value = 0
stamina.Value = 0
hunger.Value = 1
end
end
local toSave = {clan.Value, money.Value, speed.Value, strength.Value, endurance.Value, stamina.Value, hunger.Value}
game.Players.PlayerRemoving:Connect(function(player)
sentodata:SetAsync(player.UserId, toSave)
end)
end)
The output said: “attempt to index number with number”