Datastore; :GetAsync() fails on join

Hello, I am making a ban system, and as you can probably tell by the title; it has a DataStore.

Fails when the player joins.

Key:
image

Code:

--[[

[ID] = "Reason: [Reason] -- \n\n Moderator: [Username] -- \n\n Time Executed: \n [Date] \n\n If you think this was a mistake, please contact a Developer or higher."

--]]

local Banned = {}
local DDS = game:GetService("DataStoreService")
local Key = DDS:GetDataStore("DataBan_1")

game.Players.PlayerAdded:Connect(function(plr)
	
	for i,v in pairs(Banned) do
		if plr.UserId == i then
			plr:Kick("You have been script baned from this game. \n\n " .. v)
		end
	end
	
	local success, result = pcall(function()
		Key:GetAsync(plr.UserId)
	end)
	
	if not result then return end
	if result then
		if result.State == true then
			plr:Kick("\n == ADMINISTRATION SYSTEM == \n\n You have been banned from this game. \n -- \n\n Reason: \n [" .. result.Reason .. "] \n -- \n\n Moderator: \n [" .. result.Moderator .. "] \n\n Executed on: \n [" .. tostring(os.date("%c", result.Tick)) .. "] <<>> (" .. os.date("%Z", result.Tick) .. ") \n\n If you think this was a mistake, please contact a Executive or above. \n")
		end
	end
end)

Does not kick the player upon joining.

  • A. It’s a script error
  • B. Datastore server error on roblox’s side

0 voters

P.S: Most likely it’s not a roblox server datastore error, since Status+ doesn’t recognize or print it.

you are not returning anything in the pcall. Do this:

local success, result = pcall(function()
	return Key:GetAsync(plr.UserId)
end)
2 Likes

Oh… I forgot about that part… returning

1 Like
local result
pcall(function()
	result = datastore:GetAsync(key)
end)

I’ve also seen this alternative used.