Hi guys.Some days i was trying to make a inventory to my project. It was working perfectly. but when i reseted the script just broke.
i tried to add CharacterAdded but it didnt fixed the problem.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local PlayerGui = plr:WaitForChild("PlayerGui")
local Inv = PlayerGui:WaitForChild("Inventory")
local ServerInventory = game.ServerScriptService.Inventorys[plr.Name.."Inventory"]
local ClientInventory = PlayerGui.Inventory.Invbase:WaitForChild("BackColor")
local equip = PlayerGui.Inventory.Invbase.Equip.Equip
local unequip = PlayerGui.Inventory.Invbase.Equip.Unequip
local Backpack = plr:WaitForChild("Backpack")
ServerInventory.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") then
local Id = Child:FindFirstChild("iconid")
local ImageButton = Instance.new("ImageButton",ClientInventory)
selected = Instance.new("BoolValue",ImageButton)
selected.Name = "Selected"
selected.Value = false
ImageButton.Name = Child.Name
ImageButton.Image = Id.Value
ImageButton.MouseButton1Click:Connect(function()
selected.Value = true
equip.MouseButton1Click:Connect(function()
if selected.Value == true then
Child.Parent = Backpack
ImageButton:Destroy()
end --If selected == true
end)--Equip pressed
unequip.MouseButton1Click:Connect(function()
local GetAllBackPackTools = Backpack:GetDescendants()
for index, GetAllBackPackTools in pairs(GetAllBackPackTools) do
if GetAllBackPackTools:IsA("Tool") then
GetAllBackPackTools.Parent = ServerInventory
end-- if GetAllBackPackTools:IsA("Tool") then
end ---Loop for iv
end) --Unequip pressed
end)--ImageButtonPressed
end -- if Child:IsA("Tool")
end)--ChildAdded
end) --CharacterAdded
end) --PlayerAdded
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local PlayerGui = plr:WaitForChild("PlayerGui")
local Inv = PlayerGui:WaitForChild("Inventory")
local ServerInventory = game.ServerScriptService.Inventorys[plr.Name.."Inventory"]
local ClientInventory = PlayerGui.Inventory.Invbase:WaitForChild("BackColor")
local equip = PlayerGui.Inventory.Invbase.Equip.Equip
local unequip = PlayerGui.Inventory.Invbase.Equip.Unequip
local Backpack = plr:WaitForChild("Backpack")
local ChildAddedFunc = nil
ChildAddedFunc = ServerInventory.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") then
local Id = Child:FindFirstChild("iconid")
local ImageButton = Instance.new("ImageButton",ClientInventory)
selected = Instance.new("BoolValue",ImageButton)
selected.Name = "Selected"
selected.Value = false
ImageButton.Name = Child.Name
ImageButton.Image = Id.Value
ImageButton.MouseButton1Click:Connect(function()
selected.Value = true
equip.MouseButton1Click:Connect(function()
if selected.Value == true then
Child.Parent = Backpack
ImageButton:Destroy()
end --If selected == true
end)--Equip pressed
unequip.MouseButton1Click:Connect(function()
local GetAllBackPackTools = Backpack:GetDescendants()
for index, GetAllBackPackTools in pairs(GetAllBackPackTools) do
if GetAllBackPackTools:IsA("Tool") then
GetAllBackPackTools.Parent = ServerInventory
end-- if GetAllBackPackTools:IsA("Tool") then
end ---Loop for iv
end) --Unequip pressed
end)--ImageButtonPressed
end -- if Child:IsA("Tool")
end)--ChildAdded
char:WaitForChild("Humanoid").Died:Connect(function()
ChildAddedFunc:Disconnect()
end)
end) --CharacterAdded
end) --PlayerAdded
Ah yes, cause you aren’t checking for any tool that is already existing in the player’s inventory. You’re just checking whenever something gets added in the inventory, not if something already exists.
What I do usually, is using a for loop, and to create a table that contains any found element. Then, use ChildAdded, but if the child is already in the table then ignore it.