Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My pcall function keeps failing on GetAsync()?

Hey so I'm following Roblox's tutorial on data store and I am only going to post here where my problem is inside the my ModuleScript:

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

local playerData = DataStoreService:GetDataStore("Test1")
local sessionData = {}

--sets up the player when he joins
local function setupPlayerData(player)
	local playerUserId = player.UserId.."_Test1"
	local success, data pcall(function()
		data = playerData:GetAsync(playerUserId)
	end)
	if success then
		if data then
			sessionData[playerUserId] = data
		else
			sessionData[playerUserId] = {
				["Coins"] = 0,
				["Wins"] = 0
			}
		end
	else
		warn("setupPlayerData Error: cannot access data for this player")
	end
end

Players.PlayerAdded:Connect(setupPlayerData)

When I test it, It always prints/warns "setupPlayerData Error: cannot access data for this player" which is the error I put just in case the pcall fails, which is what is probably happening right now.

Any help would be greatly appreciated.

1 answer

Deleted my old post about enabling API so I could post this one... line 11 might be the issue?

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

local playerData = DataStoreService:GetDataStore("Test1")
local sessionData = {}

--sets up the player when he joins
local function setupPlayerData(player)
    local playerUserId = player.UserId.."_Test1"
    local success, data pcall(function()
        return data = playerData:GetAsync(playerUserId) --HERE Notice "return"
    end)
    if success then
        if data then
            sessionData[playerUserId] = data
        else
            sessionData[playerUserId] = {
                ["Coins"] = 0,
                ["Wins"] = 0
            }
        end
    else
        warn("setupPlayerData Error: cannot access data for this player")
    end
end

Players.PlayerAdded:Connect(setupPlayerData)

1 comment

0

Still doesnt work hmm..

This discussion is preserved as it was. New answers, comments, and votes are closed.