I made a Datastore for My game and it is not saving when I change it.
(No explaining needed)
local DataStoreService = game:GetService (“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Loyalty = Instance.new("IntValue")
Loyalty.Name = "Loyalty"
Loyalty.Parent = leaderstats
local playerUserId = "player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Loyalty.Value = data
-- Set our Data equal to the current Lotalty
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “player_”…player.UserId
local data = {
Loyalty = player.leaderstats.Loyalty.Value;
}
local data = player.leaderstats.Loyalty.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfuly saved!")
else
print("There was an error!")
warn(errormessage)
end
end)