local datastoreservice = game:GetService("DataStoreService")
local mystore = datastoreservice:GetDataStore("mydatastore")
game.Players.PlayerAdded:Connect(function(player)
local ld = Instance.new("Folder",player)
ld.Name = "leaderstats"
local coins = Instance.new("IntValue", ld)
coins.Name = "Coins"
coins.Value = 0
local playerid = "Player_" .. player.UserId
local data = mystore:GetAsync(playerid)
if data then
coins.Value = data["Coins"]
print("Data Loaded", data, data["Coins"])
else
coins.Value = 1
print("ELSE")
end
coins.Changed:Connect(function(newValue)
local datatobesaved = {
Coins = newValue
}
local success, err = pcall(function()
mystore:SetAsync(playerid, datatobesaved)
end)
if success then
print("Data saved!")
else
print("Data failed to save:", err)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local datatobesaved = {
Coins = player.leaderstats.Coins.Value;
}
local playerid = "Player_" .. player.UserId
local success, err = pcall(function()
mystore:SetAsync(playerid, datatobesaved)
end)
if success then
print("data saved!")
print(player.leaderstats.Coins.Value)
else
print("data faield to save!")
end
end)
Here is the script, the most basic, when I go into the game there is a change in explorer, coins to 100 then correctly go into the game. And again I see 1, although I changed.
There are no errors, in the settings allowed all, here are the prints: