#How to prevent camera from going back up while im still crouched?

68 messages · Page 1 of 1 (latest)

little depot
#

Maybe crouching variablr

#

Not updating

#

Correctly

#

Not sure but maybe

zenith cave
little depot
#

Maybe u are not as aware as you are fine

zenith cave
#

what

#

lol

little depot
#

Idk xd

#

Im not on pc sadly

#

So csnt code

#

Wait its 2023

#

Forgot

#
function crouch() 
    local humanoid = character:FindFirstChild("Humanoid")
    local goal = {}

    if humanoid then
        if crouching == false then
            goal.CameraOffset = Vector3.new(0,0,0)    
        elseif crouching == true then
            goal.CameraOffset = Vector3.new(0,-2.5,0)    
        end
    end    

    local crouchTween = TweenService:Create(humanoid,crouchTweenInfo,goal)
    crouchTween:Play()
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if gameProcessedEvent then return end

    if input.KeyCode == Enum.KeyCode[keybind] then
        if crouching then
            humanoid.WalkSpeed = 10
            crouching = false
            print(crouching)
            crouch() 
 
            script.Parent.up:Play()
            character.HumanoidRootPart.CanCollide =  true
        else
            humanoid.WalkSpeed = 4
            crouching = true
            print(crouching)
            crouch() 
           
            script.Parent.down:Play()
            character.HumanoidRootPart.CanCollide =  false
        end
    end
end)

local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
    humanoid:GetPropertyChangedSignal("CameraOffset"):Connect(function()
        if crouching == true then
            humanoid.CameraOffset = Vector3.new(0,-2.5,0)
        end
    end)
end
#

@zenith cave can u tell me if this helps u debugging ur problem?

zenith cave
#

alright ill try

#

real quick howd you get the code colored

little depot
#

I asked the ai to edit ur code in a way to help debugging, since im on phone, but i think the Ai did something wrong

zenith cave
#

lmao

little depot
#
--code
zenith cave
#

weird

#

i did that but it doesnt color

#

oh well

little depot
#

Maybe u forgot lua markdown

zenith cave
#

oh wait yeah i did

little depot
#

Not like I can see it colored anyway since im on mobile

zenith cave
little depot
#

Probably

#

Idk what he did , cant read, i told him something but probably he did something else

zenith cave
#

yeah all it did was add

local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
    humanoid:GetPropertyChangedSignal("CameraOffset"):Connect(function()
        if crouching == true then
            humanoid.CameraOffset = Vector3.new(0,-2.5,0)
        end
    end)
end
#

and nothing changed when i texted

#

tested*

little depot
#

Yes... never gonna ask chatGPT to code anything ever again...

zenith cave
#

😭

little depot
#

Well im home in one hour

zenith cave
#

well when you're home if you wanna help then feel free

#

i might not be online so if you wanna try the code yourself here it is

#
local keybind = "LeftShift"
local animationId = 8387703587
  
crouchTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local UserInputService = game:GetService("UserInputService")

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

TweenService = game:GetService("TweenService")

local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://' .. animationId

local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action

local crouching = false

function crouch() 
    local humanoid = character:FindFirstChild("Humanoid")
    local goal = {}

    if humanoid then
        if crouching == false then
            goal.CameraOffset = Vector3.new(0,0,0)    
        elseif crouching == true then
            goal.CameraOffset = Vector3.new(0,-2.5,0)    
        end
    end    

    local crouchTween = TweenService:Create(humanoid,crouchTweenInfo,goal)
    crouchTween:Play()
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if gameProcessedEvent then return end

    if input.KeyCode == Enum.KeyCode[keybind] then
        if crouching then
            humanoid.WalkSpeed = 10
            crouching = false
            print(crouching)
            crouch() 
            --animationTrack:Stop()
            script.Parent.up:Play()
            character.HumanoidRootPart.CanCollide =  true
        else
            humanoid.WalkSpeed = 4
            crouching = true
            print(crouching)
            crouch() 
            --animationTrack:Play()
            script.Parent.down:Play()
            character.HumanoidRootPart.CanCollide =  false
        end
    end
end)```
#

local script in starterCharacterScripts

zenith cave
#

u ever check it out

#

@little depot

little depot
#

Ah lol

#

Co pletly

#

Forgot

#

In 30 min

little depot
#

can u try

#

this

zenith cave
#

Ok later

livid dawnBOT
#

studio** You are now Level 4! **studio

zenith cave
#

Im not on my pc

little depot
#

Ok

zenith cave
#

thanks man

#

works kinda

#

doesnt tween quite right but camera works

#

i cant actually fit under small spaces though

#

yea collissions are still the same

little depot
#

Small issues right big fixes

zenith cave
#

fr

#

thanks though

little depot
zenith cave
#

yea not sure why the tween works like that though