I’ve made a script to detect if a player is in a group and if yes what is id, but somehow, I got this error:
Here the script:
local Http = game:GetService("HttpService")
game:GetService('ReplicatedStorage').Events.GetPlayerInfo.OnServerEvent:Connect(function(player, UserId)
local Table = Http:JSONDecode('https://groups.roblox.com/v2/users/' .. tostring(UserId) .. '/groups/roles')
for _, v in pairs(Table) do
if Table.group.id == 8194141 then
if Table.group.rank == 4 or Table.group.id == 255 then
return true
else
return false
end
end
end
end)
you’re not using JSONDecode() properly, you need to send a GET request using Http:GetAsync('https://groups.roproxy.com/v2/users/' ..tostring(UserId).. '/groups/roles') then put up Http:JSONDecode(result)
If I do what you said to me, I don’t have access to roblox ressources
the script:
local Http = game:GetService("HttpService")
game:GetService('ReplicatedStorage').Events.GetPlayerInfo.OnServerEvent:Connect(function(player, UserId)
local result = Http:GetAsync('https://groups.roblox.com/v2/users/' .. tostring(UserId) .. '/groups/roles')
local Table = Http:JSONDecode(result)
for _, v in pairs(Table) do
if Table.group.id == 8194141 then
if Table.group.rank == 4 or Table.group.id == 255 then
return true
else
return false
end
end
end
end)
local Http = game:GetService("HttpService")
game:GetService('ReplicatedStorage').Events.GetPlayerInfo.OnServerEvent:Connect(function(player, UserId)
local result = Http:GetAsync('https://groups.roproxy.com/v2/users/' .. tostring(UserId) .. '/groups/roles')
local Table = Http:JSONDecode(result)
for _, v in pairs(Table) do
if Table.group.id == 8194141 then
if Table.group.rank == 4 or Table.group.id == 255 then
return true
else
return false
end
end
end
end)
2 Issues, the main issue is that you aren’t making an HTTP request, so instead of the JSONDecode getting a valid json(the response of the request) it gets the url itself as the argument to decode, causing the error. The other issue is that Roblox servers can’t send requests to Roblox domains, so you must use a proxy. For serious APIs that use authentication you should not use public proxies, but since this is openly available information from a non-authentication API the risk is smaller, so you can use a proxy like roproxy.com. So your code should be:
local proxy = "roproxy.com"
local URL = "https://groups.roblox.com/v2/users/"..tostring(UserId).."/groups/roles"
local response = Http:GetAsync(URL:gsub("roblox.com", proxy))
local Table = Http:JSONDecode(response)
print(Table)
--do other things
Keep in mind there’re still risks with public proxies. For example, the proxy owner could go mad and send you false information or keep information about the IP/Roblox machine sending the request so it can DDOS it or do something malicious.
is because you’re attempting to use the JSONDecode method of the HttpService to directly parse a URL, which is not supported. The JSONDecode method is used to decode JSON string
ou need to use the HttpGetAsync method of the HttpService to fetch the JSON data from the URL, and then parse it using JSONDecode
local Http = game:GetService("HttpService")
game:GetService('ReplicatedStorage').Events.GetPlayerInfo.OnServerEvent:Connect(function(player, UserId)
local response = Http:GetAsync('https://groups.roblox.com/v2/users/' .. tostring(UserId) .. '/groups/roles')
local success, decoded = pcall(Http.JSONDecode, Http, response)
if success and decoded then
for _, group in ipairs(decoded.data) do
if group.group.id == 8194141 then
if group.group.rank == 4 or group.group.id == 255 then
return true
else
return false
end
end
end
end
end)