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

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

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

6 comments

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?

0

you may he on to something

0

Did that ever fix it?

0

rip i forgot ill do it rn

0

yeah! youre right

0

nvm now it stays there

1 answer

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

3 comments

0

If you do have any further questions about how this would work, feel free to message me on roblox.

0

the prob is that you need the player in first person

0

when setting it to the head it takes out the first person

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