Whenever player dies the button GUI stops working

  1. What do you want to achieve?
    I want the open inventory GUI to keep working even after you die.

  2. What is the issue?
    The button GUI stops working after death.

  3. What solutions have you tried so far?
    I searched up for solutions but didn’t find any.

Local Script:

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local mainInven = playerGui:WaitForChild("Inventory")
local openInventory = mainInven:WaitForChild("OpenInventory")
local inventoryGui = mainInven:WaitForChild("InventoryGui")
local openInventoryGui = mainInven:WaitForChild("OpenInventory")

openInventoryGui.TextButton.Activated:Connect(function()
	if inventoryGui.Active == true then
		inventoryGui.Visible = false
		inventoryGui.Active = false
		openInventoryGui.TextButton.Text = "Open Inventory"
		
	elseif inventoryGui.Active == false then
		inventoryGui.Visible = true
		inventoryGui.Active = true
		openInventoryGui.TextButton.Text = "Close Inventory"
		
	end
end)
1 Like

Where is the local script located?

It is in StarterPlayerScripts and the GUI is in starterGui

That’s the issue then, when you die, the Guis wont exist anymore since StarterGui will create them again and put them in the player

You can either Move the script into the button itself and change the code around

Or, at least I think it would work, disable the ResetOnSpawn property of the ScreenGui for the inventory so StarterGui wont replicate the Gui into the player when they respawn

2 Likes