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

How do you change someones camera mode back to classic?

Asked by
mnaj22 44
8 years ago
if script.Parent.Parent.Character.Humanoid.Health == 0 then
    script.Parent.Parent.Parent.Parent.CameraMode = "Classic"
end

I have the user in LockInFirstPerson, but I want it to where when he dies it changes Back to classic.

0
Where is the script located? iNicklas 215 — 8y
0
Starter Pack mnaj22 44 — 8y
0
Okay. iNicklas 215 — 8y

2 answers

Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago

The main problem here is that you're trying to use a conditional to do something when something reaches a specific value. When Lua runs through those 3 lines, it will check to see if the health is 0. If the health isn't 0 when the interpreter is looking through the code, then it just skips over to whatever's next. Let's make it so that we change the camera mode as soon as the humanoid dies. To do that, we're going to connect a function to an event. This little script should look familiar to you.

part = script.Parent

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = 0
    end
end

part.Touched:connect(onTouched)

And that kills people that touch the brick. Let's use the same principles to get what you're trying to accomplish.

function onDied()
    if script.Parent.Parent.ParentParent.CameraMode ~= "Classic" then
        script.Parent.Parent.Parent.Parent.CameraMode = "Classic"
    end
end

script.Parent.Parent.Character.Humanoid.Died:connect(onDied)

And there ya go. At the bottom, we account for the event that our poor character has died. We then connect that event to our pre-defined function, onDied.

I highly recommend learning a bit about LocalScripts and their capabilities. That way, you won't have to go script.Parent.Parent.Parent.Parent and all that jazz. Put this in a LocalScript and put it in StarterPlayerScripts in the StarterPlayer folder. Then change your player's camera mode to LockedFirstPerson, die, and see what happens.

player = game.Players.LocalPlayer

function onDied()
    if player.CameraMode ~= "Classic" then
        player.CameraMode = "Classic"
    end
end

player.Character.Humanoid.Died:connect(onDied)
Ad
Log in to vote
1
Answered by
iNicklas 215 Moderation Voter
8 years ago

put inside workspace - script not local.

game.Players.PlayerAdded:connect(function(plr) 
plr.CharacterAdded:connect(function(char)
char:WaitForChild("Humanoid")
plr.CameraMode = 1
char.Humanoid.Died:wait()
plr.CameraMode = 0

end)
end)
0
I accept your answer too, but they don't let you pick two, so feel good about yourself :D mnaj22 44 — 8y
0
Hahah :) iNicklas 215 — 8y

Answer this question