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

Why is my datastore failing when I try to getasync?

NOTE: I AM NOT ASKING FOR CODE, JUST ASKING FOR WHAT THE PROBLEM COULD BE.

Extra note: I enabled Studio Access to API services, Http Requests, etc.

Basically, it always errors when it tries to load the stats. I don't know why it does this, and it is a simple check so my scripts can see if the user completed the tutorial on how to use my admin panel.

It always says the error is just "nil" when I warn with the error message from the Protected Call (Pcall)

local DataStoreService = game:GetService("DataStoreService")

local DATASTORE = DataStoreService:GetDataStore("DeluxxeHubDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local STATS = player:WaitForChild("DeluxxePanelPlayerStats")
	wait()
	local hasTutorial = Instance.new("BoolValue")
	hasTutorial.Name = "hasTutorial"
	hasTutorial.Parent = STATS
	
	local data
	local success, errormessage pcall(function()
		wait()
		data = DATASTORE:GetAsync(player.UserId.."-tutorial")
	end)
	if success then
		hasTutorial.Value = data
	else
		print("Deluxxe Panel encountered an error while loading data... Sending error.")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		DATASTORE:SetAsync(player.UserId.."-tutorial",player.DeluxxePanelPlayerStats.hasTutorial.Value)
	end)
	if success then
		print("Deluxxe Panel Data Saved for "..player.Name)
	else
		print("Deluxxe Panel encountered an error while saving data... Sending error.")
		warn(errormessage)
	end
end)

1 answer

✓ Accepted answer

Take a look here, at line 13 in your code:

    local data
    local success, errormessage pcall(function()
        wait()
        data = DATASTORE:GetAsync(player.UserId.."-tutorial")
    end)

You're missing the assignment symbol =! The Luau compiler interprets it as

    local data
    local success, errormessage
    pcall(function()
        wait()
        data = DATASTORE:GetAsync(player.UserId.."-tutorial")
    end)

And this in part implicitly sets success and errormessage to nil. You probably want this instead:

    local data
    local success, errormessage = pcall(function()
        wait()
        data = DATASTORE:GetAsync(player.UserId.."-tutorial")
    end)

4 comments

0

OH, Thank you so much, lol! I forgot the + sign lol,

0

Where did you learn how to script gksw

0

@iivSnooxy: I learned to script through a combination of (from most to least significant) reading documentation, trial and error, peer feedback, asking questions, reading books and being taught in school.

0

= sign*

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