Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

First person is not being giving on death of player?

I want the script to give the player the FirstPerson camera mode but when the player resets are dies it does not happen Here is the code (It is in a local script in the players gui)

Player = game.Players.LocalPlayer
Clicked = false
	local player = game.Players.LocalPlayer
	Cam = workspace.CurrentCamera -- Currently not in use
	
		Player.CharacterAdded:connect(function(character)
			character:WaitForChild("Humanoid").Died:connect(function()
				if Clicked then
					character:WaitForChild("Humanoid") 
					print("The player has died")
					Player.CameraMode = Enum.CameraMode.LockFirstPerson
					print(Clicked)
			
				end
			end)
		
		end)
game.workspace.Lobby.Log.PlayButton.SurfaceGui.ImageButton.MouseButton1Click:connect(function()
	Clicked = true
	Player.CameraMode = Enum.CameraMode.LockFirstPerson
end)


1 answer

You haven't added a function, therefore it cannot happen, this one should work:


function onDied()
	Player = game.Players.LocalPlayer
	Clicked = false
	    local player = game.Players.LocalPlayer
	    Cam = workspace.CurrentCamera -- Currently not in use
	
	        Player.CharacterAdded:connect(function(character)
	            character:WaitForChild("Humanoid").Died:connect(function()
	                if Clicked then
	                    character:WaitForChild("Humanoid") 
	                    print("The player has died")
	                    Player.CameraMode = Enum.CameraMode.LockFirstPerson
	                    print(Clicked)
	
	                end
	            end)
	
	        end)
	game.workspace.Lobby.Log.PlayButton.SurfaceGui.ImageButton.MouseButton1Click:connect(function()
	    Clicked = true
	    Player.CameraMode = Enum.CameraMode.LockFirstPerson
	end
end)


game.Players.LocalPlayer.Character.Humanoid.Died:connect(onDied)

Anything gone wrong? Anything gone right? Leave a comment and I'd be happy to help.

1 comment

1

Humanoid statuses are notoriously unreliable, and in my experience, only fire half the time. Sadly, that's the best shot you have. Just a couple of corrections I'd like to make: LockFirstPerson hasn't been working online recently and should be replaced with "Player.CameraMaxZoomDistance = 0". There's also an extra ) on the end at line 23.

This discussion is preserved as it was. New answers, comments, and votes are closed.