Starter GUI: https://ibb.co/Pg00C8h
PlayerGUI Before Death: https://ibb.co/G5tbBHw
PlayerGUI After Death: https://ibb.co/7r64460
Error: https://ibb.co/Vgxk990
I am making an inventory system very similar to the one in Soybeen's "Booga Booga". It works how I want it to so far but when I respawn, I get an error that the TextLabel that display the item and # of items that is inside of the image button does not exist.
To be clear; the Inventory system seems to work perfectly fine after respawn. The amount of Grass and Wood that I have is correctly displayed as I drop stuff. The TextLabel changes it's text when I want it to even when I get the error.
Local Script:
userInputService = game:GetService("UserInputService")
player = game.Players.LocalPlayer
playerGUI = player:WaitForChild("PlayerGui")
inventoryHolderGui = playerGUI:WaitForChild("InventoryScreenGui"):WaitForChild("InventoryHolderFrame")
inventoryMainFrame = inventoryHolderGui:WaitForChild("InventoryFrame")
inventoryContents = player:WaitForChild("Inventory"):GetChildren()
inventoryButtons = inventoryMainFrame:GetChildren()
isInventoryOpen = false
mb1Debounce = false
mb2Debounce = false
--Remote Functions (not relevant to the GUI problem)
dropRequest = game.ReplicatedStorage.DropRequest
imageButtonActivated = game.ReplicatedStorage.InventoryImageButtonActivate
--Refresh all this stuff on respawn
player.CharacterAdded:Connect(function(char)
inventoryHolderGui = playerGUI:WaitForChild("InventoryScreenGui"):WaitForChild("InventoryHolderFrame")
inventoryMainFrame = inventoryHolderGui:WaitForChild("InventoryFrame")
inventoryContents = player:WaitForChild("Inventory"):GetChildren()
inventoryButtons = inventoryMainFrame:GetChildren()
end)
userInputService.InputBegan:Connect(function(input,gameProcessed)
if input.KeyCode == Enum.KeyCode.C and isInventoryOpen == false then
inventoryHolderGui = playerGUI:WaitForChild("InventoryScreenGui"):WaitForChild("InventoryHolderFrame")
inventoryMainFrame = inventoryHolderGui:WaitForChild("InventoryFrame")
inventoryContents = player:WaitForChild("Inventory"):GetChildren()
inventoryButtons = inventoryMainFrame:GetChildren()
inventoryHolderGui.Visible = true
isInventoryOpen = true
for i,v in pairs(inventoryContents) do
for o,b in pairs(inventoryButtons) do
if b.Name == v.Name then
if v.Value > 0 then
b.Visible = true
b.AmountDisplay.Text = v.Name .. " : " .. tostring(v.Value)
b.MouseButton2Down:Connect(function()
if mb2Debounce == false then
mb2Debounce = true
dropRequest:FireServer(v)
end
end)
b.MouseButton2Up:Connect(function()
if mb2Debounce == true then
mb2Debounce = false
end
end)
b.MouseButton1Down:Connect(function()
if mb1Debounce == false then
mb1Debounce = true
imageButtonActivated:FireServer(v)
end
end)
b.MouseButton1Up:Connect(function()
if mb1Debounce == true then
mb1Debounce = false
end
end)
v.Changed:Connect(function(value)
if value > 0 then
b.Visible = true
b.AmountDisplay.Text = v.Name .. " : " .. tostring(v.Value)
elseif value <= 0 then
value = 0
b.Visible = false
end
end)
elseif v.Value <= 0 then
b.MouseButton2Down:Connect(function()
dropRequest:FireServer(v)
--This creates a brick on the server and reduces v.Value by 1
end)
b.MouseButton1Down:Connect(function()
imageButtonActivated:FireServer(v)
--Reduces value by 1 on server
end)
v.Changed:Connect(function(value)
if value > 0 then
b.Visible = true
b.AmountDisplay.Text = v.Name .. " : " .. tostring(v.Value)
elseif value <= 0 then
value = 0
b.Visible = false
end
end)
end
end
end
end
elseif input.KeyCode == Enum.KeyCode.C and isInventoryOpen == true then
inventoryHolderGui.Visible = false
isInventoryOpen = false
end
end)
