--DATA STORE--
local dataStoreService = game:GetService("DataStoreService")
local mainDataStore = dataStoreService:GetDataStore("mainDataStore")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
cash.Value = mainDataStore:GetAsync(player.UserId) or 0
local subscribers = Instance.new("IntValue", leaderstats)
subscribers.Name = "Subscribers"
subscribers.Value = mainDataStore:GetAsync(player.UserId) or 0
print("Data Loaded!")
cash.Changed:Connect(function()
mainDataStore:SetAsync(player.UserId,player.leaderstats.Cash.Value,player.leaderstats.Subscribers.Value)
print("Data Saved!")
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
mainDataStore:SetAsync(player.UserId,player.leaderstats.Cash.Value,player.leaderstats.Subscribers.Value)
print("Data Saved!")
end)
end)
I know I should be using updatasync etc, still learning..
--SERVER REMOTE--
game.Workspace.Part.ClickDetector.MouseClick:Connect(function(player)
game.Workspace.Part.CashAdd:FireClient(player)
end)
--CLIENT REMOTE--
local cashAdd = game.Workspace.Part.CashAdd
local function cashAddFired(player)
game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value + 1
end
cashAdd.OnClientEvent:Connect(cashAddFired)

2 comments
Changes on the Client will not replicate to the Server, and thus cannot be saved in a DataStore, any changes you want saved should be made on the Server
So whats the fix @SeperntineKing