To increase the usefulness of my upcoming plugin, I want to be able to warn the user that my plugin won’t function properly without the datastores being enabled, but I’m unsure on how to implement this. Do I have to use a complicated workaround? or is there something I can use? Thanks in advanced
Do an api request, and if it sends back an error, then you know that they’re off.
1 Like
API services, as in datastores, I don’t think http is datastores.
1 Like
Ah, my bad - thanks for letting me know!
1 Like
No no no, there is a lot more that can go wrong with an API request than a simple access denied. Here is code to check whether Access to API is Enabled:
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")
local IsStudio = RunService:IsStudio()
local has_internet = true
local api_services_enabled = true
if IsStudio == true then
local status, message = pcall(function()
-- This will error if current instance has no Studio API access:
DataStoreService:GetDataStore("____PS"):SetAsync("____PS", os.time())
end)
local no_internet_access = status == false and string.find(message, "ConnectFail", 1, true) ~= nil
if no_internet_access == true then
has_internet = false
end
if status == false and
(string.find(message, "403", 1, true) ~= nil or -- Cannot write to DataStore from studio if API access is not enabled
string.find(message, "must publish", 1, true) ~= nil or -- Game must be published to access live keys
no_internet_access == true) then -- No internet access
api_services_enabled = false
end
end
print("Does server have internet: "..tostring(has_internet))
print("Are API services enabled: "..tostring(api_services_enabled))
@JeffTheEpicRobloxian
4 Likes
Thanks man! Really appreciate this, I’ll keep it saved for if I have to use it within any other projects
1 Like
U can wrap it in a pcall also to not crash the whole game, just make it return true of false