My datastore does not recognize when a player's leaderstat value (e.g. Money) changes. I cannot see the issue with it however and cannot figure out what is wrong (and I know that doing amount.Changed isn't the smartest thing but I can fix that later). Can anyone more experienced take a look? Here's the datastore script:
local DataStore = game:GetService("DataStoreService")
local DS1 = DataStore:GetDataStore("StatsDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leader = Instance.new("Folder", player)
leader.Name = "leaderstats"
local amount = Instance.new("StringValue", leader)
amount.Name = "yeahs"
amount.Value = DS1:GetAsync(player.UserId) or 0
DS1:SetAsync(player.UserId, amount.Value)
amount.Changed:connect(function()
print("Saving Data...")
DS1:SetAsync(player.UserId, amount.Value)
print(player.Name.."'s Data of "..amount.Value.." "..amount.Name.." has been saved.")
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
print("Saving Data...")
DS1:SetAsync(player.UserId, player.leaderstats.yeahs.Value)
print(player.Name.."'s Data of "..player.leaderstats.yeahs.Value.." "..player.leaderstats.yeahs.Name.." has been saved.")
end)
And here is the script that gives the player "yeahs" (my game's currency):
local yeahs = game.Players.LocalPlayer.leaderstats.yeahs
local sound = Instance.new("Sound", game.StarterGui)
sound.Name = "yeet"
sound.SoundId = "doesntmatterfornow"
sound.Looped = true
sound.DidLoop:Connect(function(soundId, numOfTimesLooped)
yeahs.Value = yeahs.Value + 1
--print("number "..tostring(numOfTimesLooped))
end)
sound:Play()
The datastore script is stored in ServerScriptService and the script which adds yeahs to a player's total is in a screen gui as it is tethered to the intro I made for the game. (In case you need to know this.)
EDIT: Also the script which adds "yeahs" is a LocalScript and this place does has FE on.

2 comments
Why is the ammount value set as a StringValue, shouldn't it be an IntValue?
Yup, FE isnt an option. The buttons just for decoration.