[Help needed] Userinputservice breaks after death?

hey i have a localscript inside a tool but it only works when the player first spawned in, after players death or reset it just seems to stop working completely with no error but in studio it works fine
game logs:
image
studio logs:
image

local uis = game:GetService('UserInputService')
local remote = script.Parent:WaitForChild('Remote')
uis.InputBegan:Connect(function(input, active)
	if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) and not active then
		print('FIRED BEGAN')
		remote:FireServer('down', getPlayerMouseLoc())
	end
end)


uis.InputEnded:Connect(function(input, active)
	if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) and not active then
		print('FIRED ENDED')
		remote:FireServer('up', getPlayerMouseLoc())
	end
	if script.Parent.Parent:IsA('Model') and input.KeyCode == Enum.KeyCode.Q then
		if script.Parent.Spells:FindFirstChild('Protego') then
			remote:FireServer('Qpressed', getPlayerMouseLoc())
		end
	end
end)

That’s because the tool got deleted on death. Also, is the code just not working or is it just a dev console bug?

code is working perfect in studio but in roblox it breaks after death, still no solutions

Trying doing something other than printing, it might just be a dev console-related issue. Also, try adding a wait at the beginning of the script to check when it spawns back in.