Hello. Currently i am want to set up a Build/Adventure game, where you have to fight agains NPC and mine Ores for getting a Income to Build Buildings. I have set up 2 Scripst for that.
PlayerEntered
local DataStore = game:GetService("DataStoreService"):GetDataStore("CoreStorage")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local OreMass = Instance.new("IntValue", stats)
OreMass.Name = "Mass"
local Bkills = Instance.new("IntValue", stats)
Bkills.Name = "Botkills"
local mined = Instance.new("IntValue", stats)
mined.Name = "Oresmined"
local key ="player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save format: (Bkills, mined)
Bkills.Value = savedValues(1)
mined.Value = savedValues(2)
else
local valuesToSave = {Bkills.Value, mined.Value}
DataStore:SetAsync(key, valuesToSave)
end
end)
The Values called Bkills and mined should Save, when the Player is leaving.
Script 2 Player Leaving
l~~~~~~~~~~~~~~~~~ local DataStore = game:GetService("DataStoreService"):GetDataStore("CoreStorage")
game.Players.PlayerRemoving:connect(function(player)
local key ="player-"..player.userId
--Save key:(Bkills, mined)
local valuesToSave = {player.leaderstats.Botkills.Value, player.leaderstats.Oresmined.Value}
DataStore:SetAsync(key, valuesToSave)
end)
But it wont. So i ask, what did i made wrong.

1 comment
Also sry for my Bad Grammar. I am not that good in speaking English.