StarterPlayerScript not detecting character properly?

I have created a script that will change the transparency of a model if the mouse has hovered over it and if the humanoids root part is in a certain range. I have run into quite a complicated problem. After the first death of the character, the script will stop working, I have found out that this is due to the script running off the old character model before death. I need to find a way to update the character’s variables, though I have tried to do this but have failed.

The script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character

if not Character or not Character.Parent then
	Character = Player.Character or Player.CharacterAdded:Wait()
end

local RootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local lootableItem
debounce = false

UserInputService.InputChanged:connect(function()
	if Mouse.Target then
		if Mouse.Target.Parent:FindFirstChild("Lootable") or Mouse.Target.Parent:FindFirstChild("PickUp") then
			if lootableItem ~= nil then
				lootableItem.glowBit.Transparency = 1
				lootableItem = Mouse.Target.Parent
				if (RootPart.Position - lootableItem.Node.Position).Magnitude <= 20 then
					lootableItem.glowBit.Transparency = 0
				end
			else
				lootableItem = Mouse.Target.Parent
				if (RootPart.Position - lootableItem.Node.Position).Magnitude <= 20 then
					lootableItem.glowBit.Transparency = 0
				end
			end
		elseif lootableItem ~= nil then
			lootableItem.glowBit.Transparency = 1
		end
	end
end)

Could someone give me some help?

I think the easiest way to find a solution to your problem is by putting the script in StarterCharacterScripts, as scripts in that singleton are copied to every character. “Character” in this instance would be come script.Parent. The rest of your code will probably not need to change (at first glance).