My Character variable doesn't update on death

Hi!
I’m doing something that if the bool value (CanEquip) is false, you can’t equip any tool

LocalScript

local player = game.Players.LocalPlayer
local character
repeat 
	wait()
	character = player.Character or player.CharacterAdded:Wait()
until character.Parent

--\\ CanEquip //--
character:WaitForChild("CanEquip").Changed:Connect(function()
	if character.CanEquip.Value == false then
		if character:FindFirstChildOfClass("Tool") then
			character:FindFirstChildOfClass("Tool").Parent = game.Players:FindFirstChild(character.Name).Backpack
		end
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
	else
		game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
	end
end)
--\\ OnRespawn //--
player.CharacterAdded:Connect(function()
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
end)

--\\ OnRespawn //--

player.CharacterAdded:Connect(function()

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)

end)

(No errors)

but when you reappear/Die and put the value back to false it doesn’t work
I know it is because the Character variable was not updated and I tried to fix it but i couldn’t : (

I would instead manage this CanEquip value from the Player object instead of the Player’s Character. Then you wont have to worry about redoing all the checks when the character resets.

2 Likes

Thanks, I don’t know how I didn’t think about it before xd

1 Like