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.
In order to fix your issue, you'll need to learn how to work around Filtering Enabled. Local Scripts can't make changes to the server, and Server Scripts can't get player input information and what not. In order to get around this, you need to communicate back and forth using Remote Events.
This is the video I watched to figure them out: https://www.youtube.com/watch?v=4Dc_bri9mjs
If you don't learn properly from youtube, then here's the wiki on them: https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events
You cant change a server created value from the client. You either need to change the value from the server(a regular script), or use remote events to change the value. This is due to filtering enabled. There are a few issues with the datastore script, namely using .Changed, but otherwise that should fix your issue.