I want to my create my own custom inventory and therefore tried implementing a way to drop your items. I thought this would be very easy, just parent the tool to the workspace but it turned out to be harder than I thought.
When parenting the tool to the workspace, roblox for some reason parents it to the character again. I tried finding solutions in the devForum, read through tools and tried solutions with :getPropertyChanged or a repeat - until loop but nothing worked. I’ve watched multiple tutorials but apparently it works there by just parenting it to the workspace.
Here is the part of the script:
Script
local function processDropItem(player, Item)
if Inventory[player.UserId] then
local ItemInTable = table.find(Inventory[player.UserId], Item) -- item is string
if ItemInTable then
local character = player.Character or player.CharacterAdded:Wait()
local itemAsInstance = character:FindFirstChild(Inventory[player.UserId][ItemInTable])
if itemAsInstance then
itemAsInstance.Parent = workspace
local handle = itemAsInstance:FindFirstChild("Handle") or itemAsInstance:FindFirstChild("HandleDisabled")
handle.CFrame = CFrame.new(character.HumanoidRootPart.Position + Vector3.new(0, 2, 0))
handle.Name = "HandleDisabled"
table.remove(Inventory[player.UserId], ItemInTable)
return "success"
end
else
return "error"
end
end
end
DropItem.OnServerInvoke = processDropItem
This might work to fix your problem, although to be honest I don’t know what’s causing the problem in the first place at the moment
local function processDropItem(player, Item)
if Inventory[player.UserId] then
local ItemInTable = table.find(Inventory[player.UserId], Item) -- item is string
if ItemInTable then
local character = player.Character or player.CharacterAdded:Wait()
local itemAsInstance = character:FindFirstChild(Inventory[player.UserId][ItemInTable])
if itemAsInstance then
itemAsInstance.Parent = workspace
local handle = itemAsInstance:FindFirstChild("Handle") or itemAsInstance:FindFirstChild("HandleDisabled")
handle.CFrame = CFrame.new(character.HumanoidRootPart.Position + Vector3.new(0, 2, 0))
handle.Name = "HandleDisabled"
table.remove(Inventory[player.UserId], ItemInTable)
local item = character:FindFirstChild(itemAsInstance.Name)
if item then item:Destroy() end
return "success"
end
else
return "error"
end
end
end
DropItem.OnServerInvoke = processDropItem
Thank you very much!
It parented to the character once I touched it because I changed the name of the handle after parenting it to the workspace. Now, Im changing the name first, and then parent it. Thank you for that tip