First, when I utilize one of the tools, both darkens (If equipped), and when I un-equip, the other disappeared.
Before:
After:
The Full Script:
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
repeat
wait()
until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local GUI = script.Parent
local Background = GUI.Background
local MaxSlots = 9
local Tools = Player.Backpack:GetChildren()
local NumKeys =
{
[1] = "One",
[2] = "Two",
[3] = "Three",
[4] = "Four",
[5] = "Five",
[6] = "Six",
[7] = "Seven",
[8] = "Eight",
[9] = "Nine"
}
function Init()
for _,v in pairs(Background:GetChildren()) do
if v:IsA("TextButton") then v:Destroy() end
end
for i, tool in pairs(Tools) do
if i > MaxSlots then return end
local Slot = script.TextButton:Clone()
Slot.TextLabel.Text = i
Slot.Parent = Background
Slot.Text = tool.Name
if tool.Parent == Character then
Slot.BackgroundColor3 = Color3.fromRGB(88,88,88)
end
game.UserInputService.InputBegan:Connect(function(Input, GP)
if GP then return end
if Input.KeyCode == Enum.KeyCode[NumKeys[i]] then
game.ReplicatedStorage.EquipRE:FireServer(tool, tool.Parent)
end
end)
Slot.MouseButton1Click:Connect(function()
game.ReplicatedStorage.EquipRE:FireServer(tool, tool.Parent)
end)
end
end
Init()
Character.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") and not table.find(Tools, Child) then
table.insert(Tools, Child)
Init()
end
end)
Character.ChildRemoved:Connect(function(Child)
if Child:IsA("Tool") and Child.Parent ~= Character then
table.remove(Tools, Tools[Child])
Init()
end
end)
Player.Backpack.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") and not table.find(Tools, Child) then
table.insert(Tools, Child)
Init()
end
end)
Player.Backpack.ChildRemoved:Connect(function(Child)
if Child:IsA("Tool") and Child.Parent ~= Character then
table.remove(Tools, Tools[Child])
Init()
end
end)
game.ReplicatedStorage.EquipRE.OnClientEvent:Connect(function()
for i,v in pairs(Background:GetChildren()) do
if v:IsA("TextButton") then
local Tool = Player.Backpack:GetChildren()[tonumber(v.TextLabel.Text)]
if Tool and Tool.Parent ~= Character then
v.BackgroundColor3 = Color3.fromRGB(88,88,88)
else
v.BackgroundColor3 = Color3.fromRGB(57,57,57)
end
end
end
end)
Help me.