0
votes

Hi so in my ROBLOX game I'm trying to make the inventory so that when the drop button is clicked in the GUI it drops the item beneath the player instead of where the item was picked up any idea on how to do this? Normally on mine when you press it where the item was picked up it spawns but I don't want it and I want it to spawn underneath the player and I don't know how to do that. Here is a pic of the drop script and GUI.

2
Pictures should be there not sure why they wont appear if they dont let me know and ill post again. - MikeGames
I went look through and it works for parts but not tools how do i do it for tools. - MikeGames

2 Answers

0
votes

The way I found is to transform the tool into a model and place it under the player's foot because if you only move the handle, the other parts aren't going to keep the same relative distance from each other. Because of Roblox physics, the part may spawn on the player's head(if there is no space under the player's foot). This code should be put in a local script. If you wish, you can connect the button-activated event to a remote event and use the same function there. Code:

-- Waits so the Player's backpack can load
wait(5)
local Players = game:GetService('Players')
-- Get the player Instance
local Player = Players.LocalPlayer
-- Get the default player inventory. 
local PlayerBackpack = Player:WaitForChild('Backpack')
-- Write the path to the tool you want to drop, below:
local Tool1 = PlayerBackpack:WaitForChild('Tool')
-- write the path to the Gui button, below:
local DropItemButton = script.Parent
local Offset = Vector3.new(0,0,0)

local function DropTool()
    -- Get the tool handle(main part)
    local Handle = Tool1:WaitForChild('Handle')
    Handle.CanCollide = true
    -- Creates a new model to store the Tool parts  
    local Model = Instance.new('Model')
    Model.Name = 'Tool'
    -- Get all parts, sounds, scripts... from the tool
    local ToolParts = Tool1:GetChildren()
    -- Place each part, scripts... in the model
    for _, Part in ipairs(ToolParts) do
        Part.Parent = Model
    end
    Model.PrimaryPart = Handle
    Model.Parent = workspace
    -- Get the player's left foot position and 
    -- place the tool parts there, you can choose any
    -- other body part and add a Vector3 offset
    Model:MoveTo(Player.Character:WaitForChild('LeftFoot').Position + Offset)
end 

DropItemButton.Activated:Connect(DropTool)
0
votes

You can just move where the tool is. Just use this:

local function dropTool()
   tool.Handle.CFrame = Player.Character:GetPrimaryPartCFrame()
end)

This just sets the tool's position to where the player currently is. (If its a model use SetPrimaryPartCFrame() instead or Part.CFrame)

If you have any questions make feel free to ask. If this solved your issue please make sure to mark this as the answer so other people benefit from it.