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

how do i make it drop from inventory?

Asked by 1 year ago

Well i have this script where it works like an inventory gui Rn i have made it so you lose your item when clicking on it but i want it to be copied right infront of you (player) in workspace

local button = script.Parent
button.Position = UDim2.new(0.032, 0, 0.5, 0)

local open = false


button.MouseButton1Click:Connect(function()

    open = not open

    local newPos = open and UDim2.new(0.319, 0, 0.5, 0) or UDim2.new(0.032, 0, 0.5, 0)

    button:TweenPosition(newPos, "InOut", "Quint", 0.5)
end)


local inventoryFolder = game.Players.LocalPlayer:WaitForChild("Inventory")


function updateInv()

    for i, child in pairs(script.Parent.InventoryScroller:GetChildren()) do
        if child:IsA("TextButton") then child:Destroy() end
    end

    for i, item in pairs(inventoryFolder:GetChildren()) do

        if item.Value > 0 then

            local newButton = script.ItemButton:Clone()
            newButton.ItemName.Text = item.Name
            newButton.Count.Text = item.Value

            local cam = Instance.new("Camera", newButton.ItemFrame)
            newButton.ItemFrame.CurrentCamera = cam

            local displayItem = game.ReplicatedStorage.Items[item.Name]:Clone()
            displayItem.Parent = newButton.ItemFrame

            cam.CFrame = CFrame.new(displayItem.Position + displayItem.CFrame.LookVector * 3, displayItem.Position)


            newButton.MouseButton1Click:Connect(function()

                game.ReplicatedStorage.InventoryRE:FireServer("drop", item.Name) --- here it deletes the item 
            end)

            newButton.Parent = script.Parent.InventoryScroller
        end
    end~


    script.Parent.InventoryScroller.CanvasSize = UDim2.new(0, 0, 0, script.Parent.InventoryScroller.UIGridLayout.AbsoluteContentSize.Y)
end

updateInv()

for i, item in pairs(inventoryFolder:GetChildren()) do
    item.Changed:Connect(updateInv)
end

since the item i will drop isnt specific it have something to do with the script here

1 answer

Log in to vote
0
Answered by
Wayyllon 170
1 year ago

I would recommend looking into LookVectors

It would probably be something similar to the following, but I'm not too good at math.

local HRP = Player.Character.HumanoidRootPart
local GearClone = Gear:Clone()
GearClone.Parent = game.Workspace
--Make sure that the parts of the item can collide when on the ground but not when in an inventory.

GearClone.Handle.CFrame = HRP.CFrame + (HRP.CFrame.LookVector * n)

Sorry for the somewhat poor explanation and answer but I wanted you to see this, definitely respond with the code you create and mark that as the answer as this answer probably isnt too helpful.

Ad

Answer this question