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)
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
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:
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.
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
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?
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)```