I am trying to get the ID of a pants template and using it in PromptPurchase(). Im doing this by
string.split(Pants.PantsTemplate, "id=")[2]
Basically, it splits the URL in the pantsTemplate (which is rbxasset://CODE HERE), then gets the 2nd thing in the list (which is the id)
I am receiving an error that the first parameter is an instance, not a string. (therefore i cannot split, because an instance cannot be split)
Is PantsTemplate a property of “Pants”? or is it the name of some object value that’s stored inside the “Pants” object. I ran this code in my own studio and was able to do it successfully. If you could provide a screenshot of what the pants in the explorer tab (as well as its children, if any), that would be helpful.
From the url, there is no match that has “//” in it, only one “/”, which is why the function isn’t running.
Considering there will be pants templates that will either have
“rbxassetid://” … whatever here OR
“http://www.roblox.com/asset/?id=” … whatever here, I’d use a string.sub.
local templateId = tostring(workspace.Clothing.PantsTemplate)
local id = nil
for index = 1, #templateId do
if tonumber(string.sub(templateId, index, index)) ~= nil then
id = tonumber(string.sub(templateId, index, #templateId))
break
end
end
print(id)
IF ANYONE HAS A BETTER METHOD OF DOING THIS, PLEASE CHIP IN
I’m not an expert in string manipulation
EDIT: I screwed up my code one second
EDIT #2: Here’s the fixed version
It seems like I accidently did PromptPurchase(string.split(player,PANTS, “//”))
my bad, but now it gives me an error saying “Unable to cast string to int64.”
PromptPurchase needs to things: The player instance and the ID
When you run the function, make sure that you define who the player is that you’re prompting, and make sure that the ID is in number form and not a string.