Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayerDataStore returning table instead of number? #126

Closed
kinkocat opened this issue Sep 1, 2019 · 2 comments
Closed

PlayerDataStore returning table instead of number? #126

kinkocat opened this issue Sep 1, 2019 · 2 comments
Labels

Comments

@kinkocat
Copy link

kinkocat commented Sep 1, 2019

Is this a bug? Unfinished? Or am i doing something wrong? Is there some code or documentation i can look at to answer my question? (Sorry if this is the wrong place to post this, didn't want to post it on the devforum since its strictly related to nevermore.)

The problem i am having is that PlayerData:Load("Money", 500) in my case returns a table rather than the saved value in the DataStore or even the default value. If this is correct, how am i supposed to get the stored value?

local Players 					= game:GetService("Players")
local ReplicatedStorage 		= game:GetService("ReplicatedStorage")
local DataStoreService 			= game:GetService("DataStoreService")
local ServerStorage 			= game:GetService("ServerStorage")
local MarketplaceService		= game:GetService("MarketplaceService")
local Teams						= game:GetService("Teams")

local Engine 					= require(ReplicatedStorage:WaitForChild("Nevermore"))
local require 					= Engine.require

local DataStoreManager			= require("PlayerDataStoreManager")

local DataStore = DataStoreService:GetDataStore("PlayerData")	
local PlayerDataStore = DataStoreManager.new(DataStore, function(Player)
	return "/" .. Player.UserId .. "/"
end)

local function PlayerAdded(Player)

	local PlayerData = PlayerDataStore:GetDataStore(Player)
	
        -- These values are just instanced in a seperate script.
	local Leaderstats = Player:WaitForChild("leaderstats")
	local Money = Leaderstats:WaitForChild("Money")
	Money.Value = PlayerData:Load("Money", 500) -- Won't add the saved value or the default value due to it returning a table.
	
	PlayerData:StoreOnValueChange("Money", Money)
end

for i,v in pairs(Players:GetPlayers()) do
	PlayerAdded(v)
end

Players.PlayerAdded:Connect(PlayerAdded)
@Quenty
Copy link
Owner

Quenty commented Sep 5, 2019

You’re using it wrong, sorry! It returns a promise!

I’m on mobile but will type out a better answer later.

You want to do this:

PlayerData:Load(“Money”, 500):Then(function(money)
Money.Value = money
PlagerData:StoreOnValueChanged(“Money”, Money) — Only store if we load properly
end):Catch(function(err) — handle

end)

@kinkocat
Copy link
Author

kinkocat commented Sep 5, 2019

Oh, thank you! I understand how promises work now so i can utilize more aspects of the engine. Thanks for the example (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants