Humanoid can't be updated after respawn?

--- Variables ---
local Camera = game.Workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local player = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
local Run = player:WaitForChild("Humanoid")
	--- Tween
local Tween = game:GetService("TweenService")
local Settings = TweenInfo.new(4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)
	-- Create
local ZoomOut = Tween:Create(Camera,Settings,{FieldOfView = 85})
local ZoomIn = Tween:Create(Camera,Settings,{FieldOfView = 70})

--- Script ---
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Run.WalkSpeed = 25
		ZoomOut:Play()
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Run.WalkSpeed = 10
		ZoomIn:Play()
	end
end)

.
Short story : This script work perfectly when i first joined the game (Just started). However i noticed, after i respawned / died. The sprint script just doesn’t work anymore. Other part of the script still run perfectly with no error outputted (Such as the ZoomOut tween), but not the humanoid part (Run.WalkSpeed = 25)

I putted WaitForChild() in case script was instanced before humanoid (In which, the script can’t find the humanoid). But unfortunately, that’s not the case. Anyone have idea?

I noticed the error, more likely at here:

local player = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)

Basically, the data on this variable is the player’s character, but when you die/respawn, this variable will be nil, because the character got rid off, what you could do is, connect an CharacterAdded event to an function. The CharacterAdded event is an event of an player’s instance.

Edited*

1 Like