Issue with HttpService or PlayerAdded

I’ve been trying to create a whitelist system using Json on my website for easy update etc.

I am trying to figure out why my code wouldn’t work.

Code Summary
local HttpService = game:GetService("HttpService")
local url = "http://rbx.yulxvol.com/whitelist"
local js_table = HttpService:GetAsync(url)
local whitelist = HttpService:JSONDecode(js_table)
local array = whitelist.userids

local function checkTheList(array, val)
    for k,v in pairs(array) do
        if v == val then return true end
    end
end

game.Players.PlayerAdded:Connect(function(player)
    
    if checkTheList(array, player.UserId) then
           print("Can Joined")
    else 
           print("Kicked")
    end
    
end)

I get nothing in the output at all…

Your website is returning UserIds as strings, but player.UserId is an integer. They’ll never be equal. So you either need to convert player.UserId to a string first or convert your array to numbers.

How would I go about converting a integer to string when using PlayerAdded?

Original line:

if checkTheList(array, player.UserId) then

Converting to string:

if checkTheList(array, tostring(player.UserId)) then

Thank you for the help,

But trying both

tostring()
tonumber()

Did nothing ( Meaning same blank output )

  • I could try doing a test output at the start and end

Ok, so the other problem is that your PlayerAdded event is probably not being hooked up quickly enough. You are calling your website first, which takes a little bit. So by the time it reaches the line to hook up the event, your player might already be in the game.

Therefore, it’s useful to have another routine that scans through the players in the game alongside hooking up the PlayerAdded event:

function PlayerAdded(player)
    
    if checkTheList(array, tostring(player.UserId)) then
           print("Can Joined")
    else 
           print("Kicked")
    end
    
end

game.Players.PlayerAdded:Connect(PlayerAdded)
for _,player in pairs(game.Players:GetPlayers()) do
    spawn(function() PlayerAdded(player) end)
end
2 Likes

That worked, thank you very much!

( fan of your work btw )

Thank you very much for the help!

1 Like

If you could mark his post as the solution that would be great since this has been solved.

1 Like