Script issue. Need help

hi i’m adam, i’m a beginner scripter. how would i set backpack to enabled when character gets respawned.

code:

local Player = game:GetService("Players").LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	Humanoid:UnequipTools()
end)

task.wait(game.Players.RespawnTime)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

Hello Adam,

Depending on the properties of your ScreenGui, your last 2 lines will only run when the character spawns for the first time.

I recommend placing this local script in StarterCharacterScripts, since it is dependant on character spawn.

1 Like

Your problem is happening at line 2. I changed it to the following and it worked correctly.

local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()

alright, im replacing the code right now.

did not work, did i do something wrong?

I will take a look at this too.

It didn’t worked. Still need help

I rewrote the same code into event connection based, so it should work.
Can you place this script in StarterPlayerScripts?

local Player = game.Players.LocalPlayer

Player.CharacterAdded:Connect(function(Character)
	local Humanoid = Character:WaitForChild("Humanoid")
	
	task.wait(game.Players.RespawnTime)
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	
	Humanoid.Died:Connect(function()
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		Humanoid:UnequipTools()
	end)
end)

I will take a look at this too by the way, thank you.

1 Like

I’ve put this on StarterCharacterScripts, still doesn’t work mate.

Oh. Wait it’s my fault. I didn’t put it.

The code you sent me works fine, but it doesn’t re-enable the backpack system.

The code works fine. Thank you too @umamidayo

1 Like