I’m making a system where you can pick up dropped items with a proximity prompt, which are models of an item that you get when you pick it up. You can pick up the items normally the first time, however, if you drop that item the “InteractPart” that’s welded to all the other parts and is where the proximity prompt resides in the dropped item is in a different position when you drop it, specifically, your right arm, while the rest of the model is in a different position.
Item Manager Local Script (In Gui in StarterGui)
local Gui = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MinorEvents = ReplicatedStorage:FindFirstChild("Minor Events")
local DroppedItems = workspace:FindFirstChild("Dropped Items")
local DropButton = Gui:FindFirstChild("DropButton")
local PickUpItemEvent = MinorEvents:FindFirstChild("Pick Up Item")
local DropItemEvent = MinorEvents:FindFirstChild("Drop Item")
local Player = game:GetService("Players").LocalPlayer
local GrabItemSound = Gui:FindFirstChild("Grab Item")
local function PromptPickup(droppedItem)
local PickUpPrompt = Instance.new("ProximityPrompt")
PickUpPrompt.Name = "Pick Up Prompt"
PickUpPrompt.ClickablePrompt = true
PickUpPrompt.RequiresLineOfSight = false
PickUpPrompt.ObjectText = droppedItem.Name
PickUpPrompt.ActionText = "Pick Up"
PickUpPrompt.Exclusivity = "AlwaysShow"
PickUpPrompt.MaxActivationDistance = 20
PickUpPrompt.Enabled = true
PickUpPrompt.Parent = droppedItem:FindFirstChild("InteractPart")
PickUpPrompt.Triggered:Connect(function()
PickUpItemEvent:FireServer(droppedItem)
GrabItemSound:Play()
end)
end
DroppedItems.ChildAdded:Connect(function(ItemAdded)
PromptPickup(ItemAdded)
end)
for i, droppedItem in pairs(DroppedItems:GetChildren()) do
PromptPickup(droppedItem)
end
DropButton.Activated:Connect(function()
if Player.Character:FindFirstChildOfClass("Tool") then
DropItemEvent:FireServer(Player.Character:FindFirstChildOfClass("Tool"))
end
end)
Item Manager in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Items = ReplicatedStorage:FindFirstChild("Items")
local DroppedItemsStorage = ReplicatedStorage:FindFirstChild('DroppedItems')
local MinorEvents = ReplicatedStorage:FindFirstChild("Minor Events")
local DroppedItems = workspace:FindFirstChild("Dropped Items")
local PickupItemEvent = MinorEvents:FindFirstChild("Pick Up Item")
local DropItemEvent = MinorEvents:FindFirstChild("Drop Item")
local function FindSameItem(Player, Item)
for i, PossibleItem in pairs(Player.Backpack:GetChildren()) do
if PossibleItem:FindFirstChild("ItemStats"):FindFirstChild("Name").Value == Item.Name then
return PossibleItem
end
end
for i, PossibleItem in pairs(Player.Character:GetChildren()) do
if PossibleItem:IsA("Tool") then
if PossibleItem:FindFirstChild("ItemStats"):FindFirstChild("Name").Value == Item.Name then
return PossibleItem
end
end
end
return nil
end
local function FindItemToDrop(Item)
for i, PossibleDroppedItem in pairs(DroppedItemsStorage:GetChildren()) do
if PossibleDroppedItem:FindFirstChild("Item").Value.Name == Item:FindFirstChild("ItemStats"):FindFirstChild("Name").Value then
return PossibleDroppedItem
end
end
end
PickupItemEvent.OnServerEvent:Connect(function(Player, DroppedItem)
if not FindSameItem(Player, DroppedItem:FindFirstChild("Item").Value) and #Player.Backpack:GetChildren() <= 6 then
local NewItem = DroppedItem:FindFirstChild("Item").Value:Clone()
NewItem.Parent = Player.Backpack
DroppedItem:Destroy()
elseif FindSameItem(Player, DroppedItem:FindFirstChild("Item").Value) then
local CurrentItem = FindSameItem(Player, DroppedItem:FindFirstChild("Item").Value)
if CurrentItem:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value < 30 then
CurrentItem:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value += 1
CurrentItem.Name = CurrentItem:FindFirstChild("ItemStats"):FindFirstChild("Name").Value .. " (" .. CurrentItem:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value .. ")"
DroppedItem:Destroy()
end
end
end)
DropItemEvent.OnServerEvent:Connect(function(Player, Item)
if Item:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value > 1 then
Item:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value -= 1
local DroppedItem = FindItemToDrop(Item):Clone()
DroppedItem.Parent = DroppedItems
DroppedItem.PrimaryPart.Position = Player.Character:FindFirstChild("Right Arm").Position
Item.Name = Item:FindFirstChild("ItemStats"):FindFirstChild("Name").Value .. " (" .. Item:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value .. ")"
if Item:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value == 1 then
Item.Name = Item:FindFirstChild("ItemStats"):FindFirstChild("Name").Value
end
DroppedItem.PrimaryPart.Velocity = Vector3.new(0,0,0)
elseif Item:FindFirstChild("ItemStats"):FindFirstChild("Amount").Value == 1 then
local DroppedItem = FindItemToDrop(Item):Clone()
DroppedItem.Parent = DroppedItems
DroppedItem.PrimaryPart.Position = Player.Character:FindFirstChild("Right Arm").Position
Item:Destroy()
end
end)