-
I’m trying to make it so that my custom inventory system allows users to drop tools.
-
I can drop tools that are spawned into the user’s backpack when they join, but if I add/pickup a tool it stays in backpack even if it finds the tool.
- I’ve tried switching making it print the tool name(which it does, so it’s not a issue finding the tool), and that’s about it.
Code
-- Server Script
game.ReplicatedStorage.DropTool.OnServerEvent:Connect(function(player, tool2)
print("Event fired!")
print(tool2)
local backpack = player.Backpack
for _, tool in pairs(backpack:GetChildren()) do --Loops through any tools in our tools folder
if tool.Name == tool2 then --If the tool found in the backpack is the same as the one we want to drop then
tool.Parent = workspace
end
end
end)
--Client Script
local player = game.Players.LocalPlayer
local backpack = player.Backpack
local frame = script.Parent:WaitForChild("ScrollingFrame") --Find our templates parent
local template = frame:WaitForChild("Template") --Find the template
backpack.ChildAdded:Connect(function()
for _, tool in pairs(backpack:GetChildren()) do --Loops through any tools in our tools folder
print(tool.Name.." is being added to the UI list.")
local newTemplate = template:Clone() --Clone our template everytime the loop completes
newTemplate.Name = tool.Name --Name the clone after the tool(VERY IMPORTANT)
newTemplate.ItemName.Text = tool.Name --Switch the textlabels text to the tools name
newTemplate.Visible = true --Make the button visible
newTemplate.Parent = frame --Parent the clone to our scrolling frame
local infoFrame = script.Parent.InfoFrame
newTemplate.MouseButton1Click:Connect(function() --When the button is clicked
print("Someone clicked the "..newTemplate.Name.." item.")
infoFrame.ToolName.Text = newTemplate.Name
infoFrame.ToolDrop.Visible = true
infoFrame.ToolName.Visible = true
infoFrame.ImageLabel.Visible = true
end)
local toolDrop = script.Parent.InfoFrame.ToolDrop
toolDrop.MouseButton1Click:Connect(function()
local tool2 = infoFrame.ToolName.Text
game.ReplicatedStorage.DropTool:FireServer(tool2)
end)
end
end)