Where is the script located in the first place? There’s not enough code or information on this thread to determine a source.
I’ll assume that your script is in StarterPlayerScripts since it supposedly breaks on respawn. It doesn’t actually break, your variables just reference the old character. You need to account for this case yourself via CharacterAdded.
When the player respawns, the variable “Humanoid” would still have the previous object stored to it.
(In this case, the Humanoid that was inside the player’s model BEFORE they respawned).
To fix this:
You need to place your LocalScript in “StarterCharacterScripts”
This folder places it’s contents in your player’s model thus re-initting the script when the player respawns.
Either that, or you would have to manually create a function that re-assigns your variables on the creation of a player’s new character.