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

How do you lower the players camera when pressing a key?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a crouch script for a fps. The camera is supposed to move down and up depending if they are crouching or not.

mouse.KeyDown:Connect(function(key)
    if key == "c" and crouching == 1 then
    crouching = 2
    h.WalkSpeed = h.WalkSpeed - 15
    h.JumpPower = h.JumpPower - 60
    playAnim:Play()
    cam.CFrame = cam.CFrame - Vector3.new(0,5,0)
    script.Parent.CrouchNonfication.Text = "Crouching"
    crouching = 3
    elseif key == "c" and crouching == 3 then
    crouching = 2
    h.WalkSpeed = h.WalkSpeed + 15
    if p.Perk.Value == "Kangaroo" then
    h.JumpPower = 60
    else
    h.JumpPower = 40
    end
    cam.CFrame = cam.CFrame + Vector3.new(0,5,0)
    playAnim:Stop()
    script.Parent.CrouchNonfication.Text = ""
    crouching = 1
    end
end)
end
1
Correct me if I'm wrong, but doesn't the camera need to be in "Scriptable" in order to be changed by a script? beeswithstingerss 41 — 4y
0
you may he on to something ReallyUnikatni 68 — 4y
0
Did that ever fix it? beeswithstingerss 41 — 4y
0
rip i forgot ill do it rn ReallyUnikatni 68 — 4y
View all comments (2 more)
0
yeah! youre right ReallyUnikatni 68 — 4y
0
nvm now it stays there ReallyUnikatni 68 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

One way you can do it is by setting the camera to a part that you can easily use CFrame on. PeasFactory offers a really good explanation of this that you can find here. Another way would just to keep the camera locked onto the head, which should follow your crawling animation

0
If you do have any further questions about how this would work, feel free to message me on roblox. beeswithstingerss 41 — 4y
0
the prob is that you need the player in first person ReallyUnikatni 68 — 4y
0
when setting it to the head it takes out the first person ReallyUnikatni 68 — 4y
Ad

Answer this question