I want to save 2 int values, the first one is saving, everything is fine but when i try to save the second one is not saving at all.
I looked on google for a fix, i modified the whole script as i found online and is still not working
Here is the code:
local DataStoreService = game:GetService("DataStoreService")
local KingPointsStore = DataStoreService:GetDataStore("KingPointsStore")
local tutorialStore = DataStoreService:GetDataStore('tutorialStore')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "Stats"
leaderstats.Parent = player
local King = Instance.new("IntValue")
King.Name = "KingPoints"
King.Parent = leaderstats
local tutorial = Instance.new('IntValue')
tutorial.Name = 'Tutorial'
tutorial.Parent = leaderstats
tutorial.Value = 0
local UserId = player.UserId
local kingData
local tutorialData
local success, errormessage = pcall(function()
kingData = KingPointsStore:GetAsync(UserId)
tutorialData = tutorialStore:GetAsync(UserId)
end)
if success then
King.Value = kingData
tutorial.Value = tutorialData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local UserId = player.UserId
local kingData = player.Stats.KingPoints.Value
local tutorialData = player.Stats.Tutorial.Value
KingPointsStore:SetAsync(UserId, kingData)
tutorialStore:SetAsync(UserId, tutorialData)
print('Data saved')
end)

3 comments
is still not working, could it be because i'm changing the "Tutorial" value from a local script?
Yes, that's what is causing it. The server can't read your client. You can use RemoteEvent to change the values from a server. Good luck!
indeed it worked now, thank you for the help