Howdy,
I know im dumb for asking this but i want to make it like this, so you put the ID of the badge in the TextBox and then the info appears, but i dont know how to get the text from the textbox. Can someone help me? ( i know it doesnt have sense im doing to to learn some more stuff. )
local BadgeService = game:GetService("BadgeService")
local ID = "The ID from Textbox here"
local info = BadgeService:GetBadgeInfoAsync(ID)
local Icon = script.Parent.BadgeIcon
Icon.Image = "rbxassetid://"..info.IconImageId
script.Parent.BadgeName.Text = info.Name
script.Parent.BadgeDescription.Text = info.Description
And before getting the info from the ID, make sure that ID is not nil, so that we know that the player has entered some text in the textbox. Also make sure that the ID he entered is only composed of digits using the tonumber(ID) function which will return nil if ID has letters or symbols in it.
Theres one error in the output (its nil but as i said i need to learn this better) Can you tell me what to do? :
(Line 14 is the “local info”)
local BadgeService = game:GetService("BadgeService")
local ID
script.Parent.TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
ID = script.Parent.TextBox.Text
end
end)
local info = BadgeService:GetBadgeInfoAsync(ID)
local Icon = script.Parent.BadgeIcon
Icon.Image = "rbxassetid://"..info.IconImageId
script.Parent.BadgeName.Text = info.Name
script.Parent.BadgeDescription.Text = info.Description
This tries to call GetBadgeInfoAsync on ID, which is a nil value.
Try replacing this with
local enterPressed = script.Parent.TextBox.FocusLost:Wait()
That would limit it to being used only one time, but if you’d like it to repeat, try this instead:
local BadgeService = game:GetService("BadgeService")
local ID
script.Parent.TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
ID = script.Parent.TextBox.Text
local info = BadgeService:GetBadgeInfoAsync(ID)
local Icon = script.Parent.BadgeIcon
Icon.Image = "rbxassetid://"..info.IconImageId
script.Parent.BadgeName.Text = info.Name
script.Parent.BadgeDescription.Text = info.Description
end
end)