So i have a Kill and a Money value.
I didn't know how to save multiple values so i got here
So the script looks like this :
local DataStore = game:GetService('DataStoreService')
local UserData = DataStore:GetDataStore('Data')
local Key = 'Player-'
function WhenPlayerJoin(Player)
local Leader = Instance.new('Folder')
Leader.Name = 'leaderstats'
Leader.Parent = Player
local Money = Instance.new('IntValue')
Money.Name = 'Money'
Money.Parent = Leader
local Kill = Instance.new('IntValue')
Kill.Name = "Kill"
Kill.Parent = Leader
local Data = UserData:GetAsync(Key..Player.UserId)
if Data then
Money.Value = Data[1] or 0
Kill.Value = Data[2] or 0
else
Data:SetAsync(Key..Player.UserId,{
Money.Value,
Kill.Value
})
end
end
game.Players.PlayerAdded:connect(WhenPlayerJoin)
But i keep getting this error :
ServerScriptService.DataStore:27: attempt to index local 'Data' (a number value)

3 comments
Thanks
In your for loop, putting events in loops is a bad practice. Instead make a changed event and clone the script into the leaderstats children. and make disabled to false
Just wondering, why is events in loops a bad practice?