So I tried some times to add a kills variable to my datastore script which already saves and loads one variable called strength, so that when a player kills an npc or a player the kills amount increases by 1 and then saves and loads without changing the value of other variables or resetting all of them to 0.
The problem is that when I tried adding one more variable, the game either reset my strength and kills to 0 or either doesn’t showcase both values, and I really want to add this fearture to my game, becuase it can engage more and so on.
Here is the script which I mentioned:
-- IMPORTANT --
-- For this to save you must go to Game Settings, Security, and enable Acess to API Services --
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local strength = Instance.new("IntValue")
strength.Name = "strength"
strength.Value = 0
strength.Parent = Leaderstats
local Data = DataStore:GetAsync(Player.UserId)
if Data then
strength.Value = Data
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.strength.Value)
end)
And here is its location in the game:
- Well, for implementing that, I tried a bunch of things: whatching many tutorials, looking at simmilar forums for a solution, trying some scripts on the toolbox, and even recoding the script above myself (I know some stuff), but nothing worked. So if someone can help me then I’ll thank.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.