Ad
Log in to vote
0

How Can I Use This Data Store To Find A Player Value? [closed]

Asked by 10 days ago
Edited 10 days ago

Hello! I was looking on the Developer Wiki at the data store page and I have a question. Using this data store script I found on the wiki, how would I be able to check the player's amount of money? Not sure how to go about data stores yet but how can I do something as simple as print(playerMoney) using this data store script from the wiki?

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local playerMoneyStore = DataStoreService:GetDataStore("PlayerMoneyStore")

local playerNotificationEvent = Instance.new("RemoteEvent")
playerNotificationEvent.Name = "PlayerNotificationEvent"
playerNotificationEvent.Parent = ReplicatedStorage

local playerMoney = {}

local function onPlayerAdded(player)
    local playerId = tostring(player.UserId)
    local success, money = pcall(function()
        return playerMoneyStore:GetAsync(playerId)
    end)
    if success then
        playerMoney[player] = money
    else
        playerNotificationEvent:FireClient(player, "Error retrieving saved data: please try again later")
    end

end

Players.PlayerAdded:Connect(onPlayerAdded)

Closed as Not Constructive by incapaz

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?