Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Datastore not recognizing when a value updates?

Asked by 5 years ago
Edited 5 years ago

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.

0
Why is the ammount value set as a StringValue, shouldn't it be an IntValue? Knineteen19 307 — 5y
0
Yup, FE isnt an option. The buttons just for decoration. DinozCreates 1070 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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

0
Thank you for the information and providing links to the necessary resources! I have just never gotten around to using remote events because I have never needed them ejones808 34 — 5y
0
If only FE wasn't required am I right? Knineteen19 307 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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.

0
Thank you for the response! ejones808 34 — 5y

Answer this question