I’m having some issues with the Roblox API (it’s my first time using it) and I can’t get the JSONDecode from the Official Roblox Badges.
local HttpService = game:GetService("HttpService")
game.Players.PlayerAdded:Connect(function(player)
print(player.Name, player.UserId)
local id2 = player.UserId
local IsRBXAdmin = false
local PlayerBadges = HttpService:GetAsync("https://accountinformation.roproxy.com/v1/users/"..id2.."/roblox-badges")
print(PlayerBadges)
local data = HttpService:JSONDecode(PlayerBadges)
print(data.id)
print(data.name)
print(data.description)
end)
I would send the data from the server to the client thru a remote event and then let the client handle the text box editing.
e.g.
-- server
if badgeData.name == "Veteran" then
remote:FireClient(player, "Veteran")
end
-- client
remote.OnClientEvent:Connect(function(badgeName)
TextBox.Text = badgeName
end)
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local frame = screenGui:WaitForChild("Frame")
local textbox = frame:WaitForChild("TextBox")
print(player.Name, player.UserId)
local id2 = player.UserId
local IsRBXAdmin = false
local PlayerBadges = HttpService:GetAsync("https://accountinformation.roproxy.com/v1/users/"..id2.."/roblox-badges")
print(PlayerBadges)
local data = HttpService:JSONDecode(PlayerBadges)
for _, badge in ipairs(data) do
if badge.name == "Veteran" then
textbox.Text = badge.name
end
end
end)
I’d do it like this to ensure the entire UI path has loaded before attempting to reference it further from within the same script.