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

Why is My NumberValue.Value Not Saving When Changed In Properties/Command Bar?

Asked by 5 years ago
local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local wins = Instance.new("NumberValue")
    wins.Name = "Wins"
    wins.Parent = leaderstats

    local data
    local success, errormessage = pcall(function()
        data = myDataStore:GetAsync(player.UserId.."-Wins")
    end)

    if success then
        wins.Value = data
    else
        print("data failed")
        warn(errormessage)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local success, errormessage = pcall(function()
        myDataStore:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value)
    end)

    if success then
        print("data saved")
    else
        print("data failed")
        warn(errormessage)
    end
end)

When I open up the Explorer tab, and find the value and change it in the Properties window, it does not save, even when it prints, "data saved". It also does not save when I update the value in the Command Bar. Why is that, and how can I resolve this error?

2 answers

Log in to vote
0
Answered by
Cjjdawg -9
5 years ago

Hi I am not sure this will work but you can try it:

where you have this set of code:

local data
local success, errormessage = pcall(function()
    data = myDataStore:GetAsync(player.UserId.."-Wins")
end)

if success then
    wins.Value = data
else
    print("data failed")
    warn(errormessage)
end

change to this:

local success,data = pcall(function()
    return  myDataStore:GetAsync(player.UserId.."-Wins")
end)

if success and data then 
wins.Value = data
else
 print("data failed")
    warn(errormessage)
end
0
Where is the errormessage then? Araknala 14 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
  • If you're not using API on studio, datastore won't work
  • What is NumberValue? Don't you mean IntValue? -Try changing NumberValue to IntValue, since "wins" is probably a number.
0
Yes, I turned on the API, though, you can't have an integer amount of wins. Araknala 14 — 5y

Answer this question