My script isn't working. Any ideas ?

Hi guys and girls, I recently created a scripted which I made bymyself and with the help of some people on FACEPUNCH thank you guys again ! And because I fully trust people from FACEPUNCH and stuff… I decided to ask you a question do you why it does not work ? like everything work except the part when it gets the country of the player

http.fetch doesn’t run instantly, so the callback that you’ve provided might not get the proper ply variable.

If the JSON that you get from the fetch provides the IP address that you used, you could then just loop through all players and find the player with a matching IP address.

Something like this :



hook.Add("PlayerAuthed", "CheckPlayerCountry", function( ply )
	local IPAddress = string.Explode(":", ply:IPAddress())
	IPAddress = IPAddress[1]

	if COUNTRY_WHITELIST == 1 then
	
		http.Fetch("http://ipinfo.io/" .. IPAddress .. "/json", function( str )
			local tbl, str = util.JSONToTable(str), ""
			
			if tbl['country'] != nil and tbl['country'] != "" then
			str = str .. tbl['country']
			end

			for k, v in pairs( player.GetAll() ) do
				v:IPAdress() then
				if ply:IPAdress == IPAdress then
				else
					IPAdress = ply:IPAdress
				end
				end


[editline]30th July 2015[/editline]

I think totally failed at this sorry kinda tired :slight_smile: