Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Http Service issues?

Asked by
Scriptecx 124
9 years ago

So, I'm making a Player information module, and essentially what this does is get the player information from their profile using a Roblox Http Service proxy. For some reason, it is erroring telling me that It can't find the string I'm looking for to get a user's join date. Can someone help me with this? Here's the code.

--\\ Player Information Module
--\\ Use this to get the information of a player. ie: Join Date, Place visits, etc 
--\\ HttpService must be enabled for this to work to its full extent.

local Player = {}

local HttpService = game:GetService('HttpService')

function Player:GetJoinDate(Id)
    local Link = 'http://rproxy.pw/users/'..Id..'/profile' -- The link to the players profile.
    local String = [[<p class="rbx-lead">%d+/%d+/%d+</p>]] -- A string to help find the join date. (Got from inspect element)
    local Find = HttpService:GetAsync (Link, true):match(String) -- Finds the string.
    local JoinDate = Find:match('%d+/%d+/%d+') -- Matches the join date thats inside the string.
    return JoinDate
end

return Player

Here is what it is erroring.

15:55:43.487 - Content failed because HTTP 403 (HTTP/1.1 403 Asset is not trusted for this place) 15:55:45.844 - ServerScriptService.ModuleScript:13: attempt to index local 'Find' (a nil value) 15:55:45.845 - Stack Begin 15:55:45.845 - Script 'ServerScriptService.ModuleScript', Line 13 - method GetJoinDate 15:55:45.845 - Script 'ServerScriptService.Script', Line 17 15:55:45.846 - Stack End 15:57:30.090 - Auto-Saving... 16:02:30.084 - Auto-Saving...

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

- is a special character. It means "match one or more". Thus the pattern rbx-lead does not match "rbx-lead", it matches "rbxlead" or "rbxxlead" or ...

You can escape it with %-.

You shouldn't write code that can error! If for some reason the player doesn't have it (e.g., that user doesn't exist?) then your module will error because you call :match on something that could be nil.

If Find is nil you should immediately return (probably nil to indicate failure).


You can actually avoid the second :match altogether though. You can use () to mark what part of the string you want to capture:

return HttpService:GetAsync(link, true):match [[<p class="rbx%-lead">(%d+/%d+/%d+)</p>]]
0
Thanks for the help. ;) Scriptecx 124 — 9y
Ad

Answer this question