so, i’m making a custom inventory system. i’ve looked into suggestions, and most say to preform a check when the player picks up a new tool and if it’s more than what they’re supposed to carry. if it is, delete the tool. something like this:
--THIS IS JUST EXAMPLE STUFF IT'S NOT WHAT I'M ACTUALLY USING
local maxtools = 8
local player = game:GetService("Players").LocalPlayer
local chara = player.Character or player.CharacterAdded:Wait()
chara.ChildAdded:Connect(function(item)
local invsize = player.Backpack:GetChildren()
if item:IsA("Tool") and maxtools == #invsize then
item:Destroy()
end
end)
i want to try and avoid having to delete the tool-- i want to make it so if the player tries to pick up the tool by walking over it, it instead doesn’t go into the inventory at all and rather stays on the floor. is there a way to accomplish this?
Partial solution:
You could insert a script in each Tool (inside some part of it) and verify it from there, and not make it so general elsewhere, this way the tool is simply not added
local maxtools = 8
local Tool = script.Parent.Parent
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local invsize = Player.Backpack:GetChildren()
if not maxtools == #invsize then
Tool.Parent = Player.BackPack
end
end
end)
yeah u can set the tools parent to workspace and set it like a few studs away from the character das wat i do
player.Backpack.ChildAdded:Connect(function(child)
wait(0.05)
local ToolAmount = #player.Backpack:GetChildren()
local CharacterTool = Character:FindFirstChildWhichIsA("Tool")
if CharacterTool then
ToolAmount = ToolAmount + 1
end
if ToolAmount >= 15 then
child.Parent = workspace
child.Handle.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,3,-6)
end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local backpack = player:WaitForChild("Backpack")
backpack.ChildAdded:Connect(function(child)
local toolCount = #backpack:GetChildren()
if toolCount > 8 then
child:Destroy() --destroy tool if 9th tool in backpack
end
end)
Local script, place it inside the StarterPlayerScripts folder or the StarterCharacterScripts folder.
i specified in the post i didn’t want the tool to be destroyed, but rather left alone so other players can have the opportunity to pick it up. from what it looks like, this script does the opposite of what i want
that’s a good idea, though i also wonder if this can be easily exploitable with players intentionally pushing the item to behind a wall or out of the map
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local backpack = player:WaitForChild("Backpack")
local function randNum()
return math.random(-15, 15)
end
backpack.ChildAdded:Connect(function(child)
local toolCount = #backpack:GetChildren()
if toolCount > 8 then
child.Parent = workspace
local handle = child:WaitForChild("Handle")
local hmr = character:WaitForChild("HumanoidRootPart")
handle.CFrame = hmr.CFrame + CFrame.new(randNum(), 0, randNum())
end
end)