Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I can't figure out how to make a gui that you place the id and it places the clothing?

Asked by 3 years ago

I am working on a My Hero Academia RP Game and I need to make a gui that gives clothing after the placing of a ID I need some help

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You can use the LoadAsset function.

https://developer.roblox.com/en-us/api-reference/function/InsertService/LoadAsset

Here is a simple sample script:

local textbox = -- your textbox
local InsertService = game:GetService("InsertService") -- gets the inserting service
local id = tonumber(textbox.Text) -- changing it to a number just in case lol
local asset
local model, errormsg = pcall(function() -- use a pcall to determine if the model exists
    asset = InsertService:LoadAsset(id) -- loads the asset by the id
end)

if model then -- if it does exist
    -- You can just parent the asset to the player, aka...
    asset.Parent = character -- your player's character
    -- Or you can check if it is a shirt first (i haven't tested this so idk if it will work)
    asset.Parent = workspace -- parent so that it does not return nil
    if asset:IsA("Shirt") then -- is it a shirt??
        asset.Parent = character -- your player's character
    else -- its not a shirt :(
        warn("assetId did not return a shirt") -- warning to the output
    end
else -- it doesn't exist
    warn("error loading asset")
end

Here is info for pcall() and other lua globals https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals

Hope this leads you in the right direction

Ad

Answer this question