Sprint Breaks When User Respawns

My sprint script does not work when the player respawns. i do not know why this is but it is annoying. why do you think this is?

UserInputService.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then -- Sprint
    	--// Sprint
    	Humanoid.WalkSpeed = config.runSpeed
    	canAim = false
    end
end)

UserInputService.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
    	Humanoid.WalkSpeed = config.walkSpeed
    	canAim = true
    end
end)
1 Like

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.

1 Like

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.

1 Like

ok, thank you. i think it was the old character as @ScriptingSupport said