Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

First person is not being giving on death of player?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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
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. Maxomega3 106 — 9y
Ad

Answer this question