I have a error and i do not know how to fix it. So ther error is, 1 is not a valid member of dataStore “datastoreservice.datatest” It is on line 20 btw
local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")
game.Players.PlayerAdded:Connect(function(plr)
local axes = Instance.new("Folder",plr)
axes.Name = "axes"
local Homemadeaxe = Instance.new("BoolValue",axes)
Homemadeaxe.Name = "Homemadeaxe"
local Normalaxe = Instance.new("BoolValue",axes)
Normalaxe.Name = "Normalaxe"
local success, dataofuser = pcall(ds.GetAsync, ds, plr.UserId)
if not success then
plr:Kick("Failed to load data. Please rejoin!")
end
if dataofuser ~= nil then
print("Found data for " .. plr.Name)
Homemadeaxe.Value = ds[1]
Normalaxe.Value = ds[2]
else
print("Replacing no data with new data.")
Homemadeaxe = true
Normalaxe = false
end
end)
local function save(player:Player)
local saveData = {
[1] = player.axes.Homemadeaxe.Value,
[2] = player.axes.Normalaxe.Value
}
local attempt = 0
local success
local result
repeat
success, result = pcall(ds.UpdateAsync, ds, player.UserId, function(old) return saveData end)
attempt += 1
until
success or attempt == 3
if not success then
warn(result)
end
end
local runService = game:GetService("RunService")
local players = game:GetService("Players")
game:BindToClose(function()
if runService:IsStudio() or #players:GetPlayers() <= 1 then task.wait(3) return nil end
for _, player in next, players:GetPlayers(), nil do
save(player)
end
task.wait(3)
end)
game:GetService("Players").PlayerRemoving:Connect(save)