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

How would I go about making it for sure give you the package?

Asked by 5 years ago

I have this script where if you have value, it gives you a package, but sometimes it goofs and gives you, 50 percent, 75 percent, etc. Is there anyway to fully confirm it will give you that package, there is not even an output error when it doesn't give you the full package. here is the script, its a long one.

local OUTFIT_ENDPOINT = "rbxhttp://outfit-thumbnail/image?width=420&height=420&format=png&userOutfitId="

local AssetService = game:GetService("AssetService")
local InsertService = game:GetService("InsertService")

local giver = script.Parent
local bundleId = giver:WaitForChild("BundleId")
local preview = giver:WaitForChild("Preview")

local locked = true
local bundle = Instance.new("Folder")

local function tryGet(context, object, funcName, ...)
    local success, result = pcall(object, funcName, ...)

    if success then
        return result
    else
        warn("Invalid " .. context .. ":", ..., "error:", result)
    end
end

local function setLocked(state)
    locked = state
    giver.BrickColor = locked and BrickColor.Red() or BrickColor.Green()
end

local function updateBundleId()
    -- Reset the current bundle.
    bundle:ClearAllChildren()
    setLocked(true)

    local id = bundleId.Value
    local info = tryGet("BundleId", AssetService, "GetBundleDetailsAsync", id)

    if info then
        for _,item in pairs(info.Items) do
            if item.Type == "Asset" then
                local import = tryGet("Asset", InsertService, "LoadAsset", item.Id)
                if import then
                    for _,child in pairs(import:GetChildren()) do
                        child:Clone().Parent = bundle
                    end
                end
            elseif item.Type == "UserOutfit" then
                preview.Texture = OUTFIT_ENDPOINT .. item.Id
            end
        end

        setLocked(false)
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("leaderstats").Gender.Value == 1 and character then
            wait(1)
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            local lastAppliedBundle = humanoid:FindFirstChild("LastAppliedBundle")
            if not lastAppliedBundle then
                lastAppliedBundle = Instance.new("IntValue")
                lastAppliedBundle.Name = "LastAppliedBundle"
                lastAppliedBundle.Parent = humanoid
            end

            if lastAppliedBundle.Value ~= bundleId.Value then
                local charMeshes = {}

                local oldAccessories = {}
                local newAccessories = {}

                setLocked(true)

                for _,accessory in pairs(humanoid:GetAccessories()) do
                    accessory.Parent = nil
                    table.insert(oldAccessories, accessory)
                end

                for _,child in pairs(character:GetChildren()) do
                    if child:IsA("CharacterMesh") then
                        charMeshes[child.BodyPart] = child
                    end
                end

                for _,component in pairs(bundle:GetChildren()) do
                    if component:IsA("Accessory") then
                        table.insert(newAccessories, component:Clone())
                    elseif component.Name == "R6" and humanoid.RigType.Name == "R6" then
                        local newCharMesh = component:FindFirstChildOfClass("CharacterMesh")

                        if newCharMesh then
                            local oldCharMesh = charMeshes[newCharMesh.BodyPart]
                            if oldCharMesh then
                                oldCharMesh:Destroy()
                            end

                            newCharMesh.Parent = character
                            charMeshes[newCharMesh.BodyPart] = newCharMesh
                        end
                    elseif component:IsA("SpecialMesh") or component:IsA("Decal") then
                        local head = character:FindFirstChild("Head")

                        if head then
                            local oldComp = head:FindFirstChildOfClass(component.ClassName)
                            if oldComp then
                                oldComp:Destroy()
                            end

                            local newComp = component:Clone()
                            newComp.Parent = head
                        end
                    elseif humanoid.RigType.Name == "R15" then
                        if component.Name == "R15ArtistIntent" then 
                            for _,limb in pairs(component:GetChildren()) do
                                humanoid:ReplaceBodyPartR15(limb.Name, limb:Clone())
                            end
                        elseif component.Name == "R15Anim" then
                            local animate = character:FindFirstChild("Animate")
                            if animate then
                                for _,newAnim in pairs(component:GetChildren()) do
                                    local oldAnim = animate:FindFirstChild(newAnim.Name)
                                    if oldAnim then
                                        oldAnim:Destroy()
                                    end

                                    newAnim:Clone().Parent = animate
                                end
                            end
                        end
                    end
                end

                local accessories = (#newAccessories > 0 and newAccessories or oldAccessories)

                for _,accessory in pairs(accessories) do
                    humanoid:AddAccessory(accessory)
                end

                if humanoid.RigType.Name == "R15" then
                    humanoid:BuildRigFromAttachments()
                end

                lastAppliedBundle.Value = bundleId.Value
                setLocked(false)
            end
        end
    end
    end)
    end)

updateBundleId()

bundleId.Changed:Connect(updateBundleId)

Answer this question