My database isnt working

I don’t see any errors.

Module

local json = {}
json.query = function(...)
	local args = {...} 
	local server = game:GetService("HttpService")
	local web = "https://api.rampagestudios.org/operation-foxtrot/api/"
	local auth = "studio" 
	if args[1] == "POST" then
		if args[3] ==  args[3] then
			local data = server:JSONEncode(args[2])
			local jsonData = server:PostAsync(web, data, Enum.HttpContentType.ApplicationJson)
			return jsonData
		else
			return "Access Denied to HTTPS JSON"
		end
	end
	if args[1] == "GET" then
		if args[3] ==  args[3] then
			local data = server:JSONEncode(args[2])
			local jsonData = server:GetAsync(web, data, Enum.HttpContentType.ApplicationJson)
			return jsonData
		else
			return "Access Denied to HTTPS JSON"
		end
	end
end
return json

The Script

-- Copyright 2020 Rampage Interactive LLC
-- Primary written by: vq9o
local json = require(game.ReplicatedStorage.Modules.JSON)
game.Players.PlayerAdded:Connect(function(player)
	local key = "studio"
	sessionStart(player)
	-- scripting php in the other tab..
	local leaderstats = Instance.new("Folder", player)
	local sessionBan = json.query("POST", {target = player.UserId, type = "sessionBanCheck", auth = key}, key)
	if sessionBan.response == 1 then
		player:Kick("Disconnected from session \n You have been banned from the game by ".. sessionBan.admin .." for ".. sessionBan.reason ..". \n Unbanned on ".. sessionBan.date)
	end
	-- Cash
	local cash = json.query("POST", {target = player.UserId, type = "fetchCash", auth = key}, key)
	if cash.response == 1 then
		json.query("POST", {target = player.UserId, type = "createaccount", auth = key}, key)
		wait(1.5)
		player:Kick("Disconnected from session \n We had a problem loading your account. Please rejoin")
	else
		local cashv = Instance.new("IntValue", leaderstats)
		cashv.Name = "Cash"
		leaderstats.Name = "leaderstats"
		cashv.Value = cash.amount
	end
	-- Exp 
	local exp = json.query("POST", {target = player.UserId, type = "fetchExp", auth = key}, key)
	if exp.response == 1 then
		json.query("POST", {target = player.UserId, type = "createaccount", auth = key}, key)
		wait(1.5)
		player:Kick("Disconnected from session \n We had a problem loading your account. Please rejoin")
	else
		local expv = Instance.new("IntValue", leaderstats)
		expv.Name = "Exp"
		leaderstats.Name = "leaderstats"
		expv.Value = exp.amount
	end
end)

function sessionStart(player)
	local sessionTime = 0;
	game.ReplicatedStorage.Remotes.Notifications:FireClient(player, "white", "Account information loaded", 7)
	while wait(0.1) do
		sessionTime = sessionTime + 1
	end
end

We’re going to need more information than “My database isn’t working” to help figure out what’s wrong.

What have you tried so far? What exactly is not working with your scripts?

I’m noticing a couple of things here off the bat that either make little sense or are incorrect:

if args[3] == args[3] then

Obviously, args[3] is going to equal args[3], so this if-else block is redundant

You’re also using GetAsync incorrectly. GetAsync does not take in a content type nor any data to send as it is a GET request, not a POST request. If you look at the documentation for GetAsync, you’d see it takes in three parameters: URL, nocache, and headers, while you’re passing in a URL, data, and a content type.

Also, I would recommend wrapping any HTTP requests in a pcall as there’s always a chance that the requests will fail and error out.

https://developer.roblox.com/en-us/api-reference/function/HttpService/GetAsync

1 Like