Do u know why it doesn’t work?
You also need to check for tools in the player’s character using a for loop
how do that can u explain it me maybe?
local numberOfTools = 0
for i,v in pairs(Character:GetChildren()) do
if v:IsA("Tool") then
numberOfTools += 1
end
end
Basically when looking at the explorer tab when a tool isn’t equipped it’s in the player tab parented under Backpack, when a player equips the tool it gets parented to the actual model of the player in workspace and just gets thrown into the character. That’s why you check for tools in the character but also the backpack of the player.
Do this:
local itemsInBackpack = #game.Players.PlayerName.Backpack:GetChildren()
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local ToolCount = 0
local Backpack = Player:WaitForChild("Backpack")
while wait(1) do
for i, v in pairs(char:GetChildren()) do
if v:IsA(“Tool”) then
ToolCount += 1
end
end
script.Parent.Text = tostring(#Backpack:GetChildren() + ToolCount)
ToolCount = 0
end
Hope this helps
2 Likes
Thank you very much, now this finally works for me
Use events.
local Game = game
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Backpack = Player:FindFirstChildOfClass("Backpack") or Player:WaitForChild("Backpack")
local function OnChildChanged(Child)
if not (Child:IsA("BackpackItem")) then return end
task.wait()
local Count = if Child:IsDescendantOf(Character) then 1 else 0
Count += #Backpack:GetChildren()
print(Count)
end
Character.ChildAdded:Connect(OnChildChanged)
Character.ChildRemoved:Connect(OnChildChanged)
Backpack.ChildAdded:Connect(OnChildChanged)
Backpack.ChildRemoved:Connect(OnChildChanged)
2 Likes