im working on a game and i run into 1 error its at line 22
Server script:
local template = script.Parent.Template
local TemplateInfo = template["Text info"]:Clone()
local TemplateImage = template.ItemImage:Clone()
local TemplateName = TemplateInfo.name
local TemplateDescription = TemplateInfo.Description
local TemplateImageImage = TemplateImage.ImageLabel
local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.ReleaseItem.MouseButton1Click:Connect(function()
local ASSET_ID = tonumber(script.Parent.ItemID.Text)
local MarketplaceService = game:GetService("MarketplaceService")
local insertService = game:GetService("InsertService")
script.Parent.ReleaseItem.MouseButton1Click:Connect(function()
local ASSET_ID = tonumber(script.Parent.ItemID.Text)
local asset = MarketplaceService:GetProductInfo(ASSET_ID) -- line 22
TemplateName.Text = asset.Name
TemplateDescription.Text = asset.Description
local model = insertService:LoadAsset(ASSET_ID)
local Info1 = TemplateImage
local info2 = TemplateInfo
Info1.Parent = model
Info1.Adornee = model
info2.Parent = model
info2.Adornee = model
model.Parent = workspace
end)
end)
The comment is placed under an if statement that checks if ASSET_ID is not nil (basically, if ASSET_ID is a number in this case). In this context, you can replace the comment with lines 23-33 from your original code.
If you want to only keep the number part of the string, you can do the following:
--two-lined on purpose, else it errors due to the second value gsub returns
local numbersOnly = script.Parent.ItemID.Text:gsub("%D", "")
local ASSET_ID = tonumber(numbersOnly)
Basically, the first line removes all non-numerical characters from the string(for example “5$” becomes 5) and the second line changes the datatype from a string to a number.
What gsub does is that it replaces all occurrences of the first argument with the second one, so every time it finds "%D" it replaces it with ""(basically it removes it, by replacing it with nothing). %D is a string pattern. In Roblox string patterns “%d” means all numbers and when a pattern is capitalized it means the opposite, so “%D” means all characters that aren’t numbers. So the entire first line translates to “replace all characters that aren’t a number with the empty character”.