I'm getting the error ServerScriptService.Datastore2:17: attempt to index local 'storedvalues' (a number value) and I'm not sure why
ServerScript 1
local DS = game:GetService("DataStoreService"):GetDataStore("test-001")
game.Players.PlayerAdded:Connect(function(plr)
local hiddenstats = Instance.new("Folder")
hiddenstats.Name = "hiddenstats"
hiddenstats.Parent = plr
local Energy = Instance.new("IntValue")
Energy.Name = "Energy"
Energy.Parent = hiddenstats
Energy.Value = 100
local key = "User-" .. plr.userId
local storedvalues = DS:GetAsync(key)
if storedvalues then
Energy.Value = storedvalues[1] -- This is the source
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local items = (plr.hiddenstats.Energy.Value)
local key = "User-" .. plr.userId
DS:SetAsync(key, items)
end)
I'm not the best at datastores if somebody could explain why I'm having this error and how to fix it, that would be nice ^_^ .

1 comment
I know it's not leaderstats. I did that on purpose, so it wouldn't show up on the leaderboard.