Remote ban only works on join

Hello.

Earlier my remote ban script worked every 10 seconds.
But now it only works when you join the game.
After that, it fails.
I see it says 500 internal errthe or, but website works fine.

Do anyone have suggestions on how to improve this script?
And perhaps make a way to send from roblox to the MySQL database without having a password in the script (Another way to verify)

https://mas.newstargeted.com/Bans.php?Bans=1
https://mas.newstargeted.com/Bans.php?Bans=4309939


image

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

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

game.Players.PlayerAdded:connect(function(Player)
    local result = http:GetAsync(serveruri..Player.userId)
    print(result)
    local result = http:JSONDecode(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)

while wait(10) do
    for _,Player in pairs (game.Players:GetPlayers()) do
        local result = http:GetAsync(serveruri..Player.userId)
        print(result)
        local result = http:JSONDecode(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

The link says that the “page isn’t working.” You should just paste your code and indent it to make it appear like actual lua code

   local example

Not sure what you mean?

game.Players.PlayerAdded:connect(function(Player)
local result = http:GetAsync(serveruri…Player.userId)
print(result)
local result = http:JSONDecode(result)

it’s Player.UserId, not Player.userId?
and also I suggest you make it send a batch of userIds, then the server respond with user that is supposed to be banned
like

while task.wait(10) do
    local userIds = {}
    for _,Player in pairs (game.Players:GetPlayers()) do
        table.insert(userIds, Player.UserId)
    end

    --send a request to your web server with the userIds
end

because roblox limits to 500 requests per minute, and you can just remove the PlayerAdded event and only keep the while true code to check

also you can just do result.banned instead of result["banned"] it makes your code look cleaner (to me) and why are you using string instead of booleans? like result.banned == "True" instead of result.banned == true or just if result.banned then

Player.UserId is not valid on roblox.
Player.userId works, but gives error for some reason.

I did try and re-write it below, but it still gives this error:
HTTP 500 (Internal Server Error) - Server - RemoteBan-Test3:10
local result = http:GetAsync(serveruri..Player.userId)

Do you have any suggestions on how to fix this?

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

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

game.Players.PlayerAdded:connect(function(Player)
	local result = http:GetAsync(serveruri..Player.UserId)
	print(result)
	local result = http:JSONDecode(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)

while true do
	wait(60) -- wait for a minute before checking the next batch of users

	local players = game.Players:GetPlayers()
	local UserIds = {}
	for _,Player in pairs(players) do
		table.insert(UserIds, Player.UserId)
	end

	local result = http:GetAsync(serveruri..table.concat(UserIds, ","))
	local result = http:JSONDecode(result)

	for i,Player in pairs(players) do
		if result[i]["error"] then
			print(result[i]["error"])
		elseif result[i]["banned"] == "True" then
			RemoveFromGame(Player)
			print('Player "'..Player.Name..'" is banned and therefore removed from the game.')
		elseif result[i]["banned"] == "False" then
			print('Player "'..Player.Name..'" is not banned.')
		else
			print('Unkown response')
		end
	end
end

Write down a map of your server response logic and find a place where it doesn’t respond.
(It could be anything, so checking the server is the first step)
Like it should look like this:
If GET then:

elseif POST then:

elseif PUT…

I figured out the issue, but not the solution to it yet.
When using the URL below it errors for some reason with no result.
It is the same content in both URLs, with no changes at all.

All folder permissions to the subdomain and main domain are the same also.
https://mas.newstargeted.com/mas/Bans.php?Bans=4309939 HTTP ERROR 500

But if I use the URL below it works.
https://newstargeted.com/mas/Bans.php?Bans=4309939 {"banned":"False"}

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
		warn("An error occurred when connecting to the website: " .. result)
		return
	end

	result = http:JSONDecode(result)
	if result.error then
		warn(result.error)
	elseif result.banned == "True" then
		removeFromGame(player)
		print(player.Name .. ' is banned and has been removed from the game.')
	elseif result.banned == "False" then
		print(player.Name .. ' is not banned.')
	else
		warn('Unknown 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
		warn("An error occurred when connecting to the website: " .. result)
		return
	end

	result = http:JSONDecode(result)
	if result.error then
		warn(result.error)
	elseif result.banned == "True" then
		print(player.Name .. ' is banned and has been removed from the game.')
	elseif result.banned == "False" then
		print(player.Name .. ' is not banned.')
	else
		warn('Unknown 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
			warn("An error occurred when connecting to the website: " .. result)
			return
		end

		result = http:JSONDecode(result)
		if result.error then
			warn(result.error)
		elseif result.banned == "True" then
			removeFromGame(player)
			print(player.Name .. ' is banned and has been removed from the game.')
		elseif result.banned == "False" then
			print(player.Name .. ' is not banned.')
		else
			warn('Unknown response')
		end
	end
end

Have you tried requesting via webbrowser?
I can tell it’s a server issue.


This is what happens when I request id of 1

Yeah i know it says error 500.
I just don’t know why it would error, since it’s only a copy of domain/mas/
It only returns if the user is banned.
Else it returns internal error.

Well I want to tell you that it doesn’t give an error when I request other user id than the 4…
Perhaps you have reversed booleans and somehow it caused server to error?

Hm, i tried with your ID also, but it errored.

Here’s the small script to check from the website to the database (Yes there is more to this script, but this is what it returns.)
image

What does “count” function do?
I mean it definitely returns a number, but what’s inside?

Try to find the requested user id’s in the database.
4309939
1
Also try echoing what does the $exist return

My user i have added a number 1 behind it just to not ban my self.
43099391
And 1 is listed because I wanted to test the system.
image

To the fact, https://mas.newstargeted.com/Bans.php?Bans=4309939 doesn’t return the error. So it probably gives you the HTTP error.

But why would that URL error and not https://newstargeted.com/mas/Bans.php?Bans=4309939 this one?


looks like you have typo and that’s why server was erroing. Just for the future try returning a server response class where it contains {error: null | string, value: “your response”}, so roblox http requests don’t give an error too.
Everything else with your server works just right.

Nevermind I found out those websites are run on the same servers

Also could you show what's in [https://newstargeted.com/mas/Bans.php](https://newstargeted.com/mas/Bans.php?Bans=4309939) ?
(The SQL fragment and the "count" function)```

both of the urls have the same code in them.

image

https://newstargeted.com/mas/Bans.php?Bans=4309939 Now shows this, if that is what you asked for?
{"error":null,"value":"False"}

Summary
<?php

$db = mysqli_connect("localhost", "DB_Name", "DB_Password","DB_Username");
$yourVariable = mysqli_real_escape_string($db,$_GET['Database']);

// Check connection
if (mysqli_connect_errno()) {
  $response = array(
    "error" => "Failed to connect to the database.",
    "value" => null
  );
  echo json_encode($response);
} else {
	if (is_numeric($yourVariable)) {
		$exist = mysqli_query($db, "SELECT * FROM Database WHERE `Databasetable`.`name` = ".$yourVariable); 
		$exist = mysqli_fetch_array($exist);
		if (count($exist) > 0) {
      $response = array(
        "error" => null,
        "value" => "True"
      );
      echo json_encode($response);
		} else {
      $response = array(
        "error" => null,
        "value" => "False"
      );
      echo json_encode($response);
		}
	} else {
    $response = array(
      "error" => "ID received was not numerical.",
      "value" => null
    );
    echo json_encode($response);
	}
}

mysqli_close($db);

?>


Yeah, like this, with help of objects to make it simpler (keep in mind server response map might grow, that’s why I created functions for that case)