Remote ban only works on join

I tried this rewrite, but it does not seem to give any output or reactions at all.

Summary
local serveruri = 'https://newstargeted.com/mas/Bans.php?Bans='
local http = game:GetService('HttpService')

local function removeFromGame(player)
	player:Kick("You have been kicked for exploiting")
end

game.Players.PlayerAdded:Connect(function(player)
	local success, result = pcall(function()
		return http:GetAsync(serveruri .. player.UserId)
	end)
	if not success then
		local response = {
			error = "An error occurred when connecting to the website: " .. result,
			value = nil
		}
		return response
	end

	result = http:JSONDecode(result)
	if result.error then
		local response = {
			error = result.error,
			value = nil
		}
		return response
	elseif result.banned == "True" then
		removeFromGame(player)
		local response = {
			error = nil,
			value = player.Name .. ' is banned and has been removed from the game.'
		}
		return response
	elseif result.banned == "False" then
		local response = {
			error = nil,
			value = player.Name .. ' is not banned.'
		}
		return response
	else
		local response = {
			error = 'Unknown response',
			value = nil
		}
		return response
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, result = pcall(function()
		return http:GetAsync(serveruri .. player.UserId)
	end)
	if not success then
		local response = {
			error = "An error occurred when connecting to the website: " .. result,
			value = nil
		}
		return response
	end

	result = http:JSONDecode(result)
	if result.error then
		local response = {
			error = result.error,
			value = nil
		}
		return response
	elseif result.banned == "True" then
		local response = {
			error = nil,
			value = player.Name .. ' is banned and has been removed from the game.'
		}
		return response
	elseif result.banned == "False" then
		local response = {
			error = nil,
			value = player.Name .. ' is not banned.'
		}
		return response
	else
		local response = {
			error = 'Unknown response',
			value = nil
		}
		return response
	end
end)

while true do
	wait(10)
	for _, player in pairs(game.Players:GetPlayers()) do
		local success, result = pcall(function()
			return http:GetAsync(serveruri .. player.UserId)
		end)
		if not success then
			local response = {
				error = "An error occurred when connecting to the website: " .. result,
				value = nil
			}
			return response
		end
		result = http:JSONDecode(result)
		if result.error then
			local response = {
				error = result.error,
				value = nil
			}
			return response
		elseif result.banned == "True" then
			removeFromGame(player)
			local response = {
				error = nil,
				value = player.Name .. ' is banned and has been removed from the game.'
			}
			return response
		elseif result.banned == "False" then
			local response = {
				error = nil,
				value = player.Name .. ' is not banned.'
			}
			return response
		else
			local response = {
				error = 'Unknown response',
				value = nil
			}
			return response
		end
	end
end

Check if the http:GetAsync function gets called (I know it might sound ridiculous as it’s clearly triggered on player join, but do what i’ve said)

I ended up going for this script for now on the Lua side.
Until I can figure out why https://mas.newstargeted.com/Bans.php?Bans=4309939 just gives an internal 500 error :confused:

Summary
local HttpService = game:GetService("HttpService")

serveruri = 'https://newstargeted.com/mas/Bans.php?Bans='
--serveruri = 'https://mas.newstargeted.com/Bans.php?Bans='

function RemoveFromGame(Player)
	Player:Kick("You have been Kicked for exploiting") -- you can replace this with your own method of kicking, e.g. a crash script
end

function safeReq(url)
	local success, result = pcall(function()
		return HttpService:GetAsync(url)
	end)
	if success then
		return true, result
	else
		return false, result
	end
end

function processStatus(statusCode, result)
	if statusCode == 200 then
		-- process result
	else
		-- handle error
	end
end

game.Players.PlayerAdded:connect(function(Player)
	local success, result = safeReq(serveruri..Player.userId)
	if not success then
		print("Error making request: " .. result)
	else
		processStatus(200, result)
		if result["error"] then
			print(result["error"])
		elseif result["banned"] == "True" then
			RemoveFromGame(Player)
			print('Player "'..Player.Name..'" is banned and therefore removed from the game.')
		elseif result["banned"] == "False" then
			print('Player "'..Player.Name..'" is not banned.')
		else
			print('Unkown response')
		end
	end
end)

while wait(10) do
	for _,Player in pairs (game.Players:GetPlayers()) do

		local success, result = safeReq(serveruri..Player.userId)
		if not success then
			print("Error making request: " .. result)
		else
			processStatus(200, result)
			if result["error"] then
				print(result["error"])
			elseif result["banned"] == "True" then
				RemoveFromGame(Player)
				print('Player "'..Player.Name..'" is banned and therefore removed from the game.')
			elseif result["banned"] == "False" then
				print('Player "'..Player.Name..'" is not banned.')
			else
				print('Unkown response')
			end
		end
	end
end

print(newPlayer.Name..", If you see this, it means that the RemoteBan works.")

I managed to fix up my script fully @fgfbfrj

You can see it below.
The only thing I’ve not made yet is that it only tries to get updates when the Database is updated and when the user joins.

PS: Script requires a discord webhook URL to report, and will error without one.
Mas-Remote-ban.rbxm (4.9 KB)

Yeah, i still haven’t figured out why it errors out on the sub domain :confused:

Have you tried rebooting the server?

Yeah, i have rebooted, i have also added this to htaccess since Cloudflare is strict on origin.

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "OPTIONS,POST,GET,HEAD,DELETE,PUT"
Header always set Access-Control-Allow-Headers "x-requested-with,Content-Type,origin,authorization,accept,client-sent-security-token"
Header always set Access-Control-Expose-Headers "Content-Security-Policy, Location"