How to prevent startergui backpack from being disabled

I have a grenade script with a local and server script, when the tool is activated the local script handles the animations and temporarily disables the startergui backpack until the tool is activated again (because if you could unequip the grenade it would break). The only problem is, I decided to add in a timer so if it goes off it will blow up in your hand, but when you die due it blowing up in your hand your backpack gui does not re enable, causing the player to be unable to equip items in the backpack, here is the script:

local plr = game.Players.LocalPlayer
local char = plr.Character
while not char or not char.Parent do
	char = plr.Character
	wait()
end

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local AnimTrack1 = humanoid:LoadAnimation(script.Parent.Aim)
local AnimTrack2 = humanoid:LoadAnimation(script.Parent.Throw)
local AnimTrack3 = humanoid:LoadAnimation(script.Parent.PinPull)
local mouse = player:GetMouse()
local startergui = game:GetService("StarterGui")
local activating = false
local active = false

script.Parent.Activated:Connect(function()
	if activating == false and active == false then
		startergui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		activating = true
		AnimTrack3:Play()
		AnimTrack3.Stopped:Connect(function()
			AnimTrack1:Play()
			activating = false
			active = true
		end)
	end
end)



script.Parent.Activated:Connect(function()
	if active == true then
		script.Parent.Handle.Throw:FireServer(mouse.Hit)
		startergui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		AnimTrack1:Stop()
		AnimTrack2:Play()
	end
end)

I tried previously to make a local script that checks when a player is added and set the backpack gui to true but it didn’t work, any solutions?

Nevermind, I found my own solution.

1 Like