Local script stops working after player respawns

I have a local script in starterplayerscripts that changes a player’s camera mode whenever they enter or exit a seat, it works fine when I first try to use the script, but when the player dies, respawns, and then tries to enter a seat again, the script doesn’t work anymore.

Here is the script, how could I fix this?

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera

char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
	if isSeated then
		print("player is seat")
		plr.CameraMode = Enum.CameraMode.Classic
		plr.CameraMaxZoomDistance = 70
		plr.CameraMinZoomDistance = 30
	end

	if not isSeated then 
		print("player is not in seat")
		plr.CameraMode = Enum.CameraMode.LockFirstPerson
		plr.CameraMaxZoomDistance = 0.5
		plr.CameraMinZoomDistance = 0.5
		return 
	end
end)

When the player dies their character is remade, therefore your character’s humanoid seated event doesn’t exist anymore either, I think it would be best to maybe put this script in StarterCharacterScripts so it’s remade when a character is made again

To explain the difference, StarterPlayerScripts are cloned when the Player instance is made, kinda like PlayerAdded, StarterCharacterScripts are cloned when character instances are made, like CharacterAdded

2 Likes

Or made this function update everytimes you respawns

Thanks! I didn’t realize the difference between startercharacter and starterplayer.

1 Like