How do I disable a function = function?

So I making a crouch system and tryin’ to sync it with movement script. I added a function = function when character crouched, it does worked but I want it disable when my character stands up

	UserInputService.InputBegan:Connect(function(input:InputObject,Key)
		if input.KeyCode == Enum.KeyCode.C then
		     Anima.WalkForward = Crouchmove
                     CrouchAnim:Play()
	end)
	
	UserInputService.InputBegan:Connect(function(input:InputObject,Key)
		if input.KeyCode == Enum.KeyCode.X then
                 Anima.WalkForward = Crouchmove = false --- ??? yeah im having big problem at here, i dont know how to disable this.
                 CrouchAnim:Stop()
	end)
2 Likes

Doing :Stop() should be enough, what’s the problem?

1 Like

Whats crouchmove? Is it a boolean or just a variable without nothing

2 Likes

boolean idk what to put these to stop.

1 Like

well the problem is I’m using stand forward animation, so when im crouch down I make the stand forward animation = crouch move animation too. But now when I stands up it still using the crouch move animation.

1 Like
UserInputService.InputBegan:Connect(function(input:InputObject,Key)
		if input.KeyCode == Enum.KeyCode.X then
                 Anima.WalkForward = Crouchmove
                 Crouchmove = false
                 CrouchAnim:Stop()
	end)

Something like this?

1 Like

Well then use InputEnded? I think you can put all that code in one…?

UserInputService.InputBegan:Connect(function(input:InputObject,Key)

end)

Okay can you tell me what exactly is the problem right now.

1 Like

actually here is the full code:

local RunService = game:GetService('RunService')
local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
local Humanoid = Character:WaitForChild('Humanoid')

local AnimationsFolder = script:WaitForChild('Animations')
local CrouchSoundsFolder = AnimationsFolder.Sounds
local CrouchSounds = CrouchSoundsFolder.Crouch
local CrouchGetUp = CrouchSoundsFolder.GetUp

local CrouchIdleAnim = Humanoid:LoadAnimation (AnimationsFolder.CrouchIdle)
CrouchIdleAnim.Looped = true
CrouchIdleAnim.Priority = Enum.AnimationPriority.Idle

local CrouchMoveAnim = Humanoid:LoadAnimation (AnimationsFolder.CrouchMove)
CrouchMoveAnim.Looped = true
CrouchMoveAnim.Priority = Enum.AnimationPriority.Action

local stanceChangeTime = 0.3

local AnimationsTable = {

	['Idle'] = Humanoid:LoadAnimation( AnimationsFolder.Idle ),
	
	['WalkForward'] = Humanoid:LoadAnimation( AnimationsFolder.WalkForward ),
	['WalkRight'] = Humanoid:LoadAnimation( AnimationsFolder.WalkRight ),
	['WalkLeft'] = Humanoid:LoadAnimation( AnimationsFolder.WalkLeft ),

}

for _, Animation in AnimationsTable do

	Animation:Play( 0, 0.01, 0 )

end

RunService.RenderStepped:Connect(function()

	local DirectionOfMovement = HumanoidRootPart.CFrame:VectorToObjectSpace( HumanoidRootPart.AssemblyLinearVelocity )

	local Forward = math.abs( math.clamp( DirectionOfMovement.Z / Humanoid.WalkSpeed, -1, -0.01 ) )
	local Backwards = math.abs( math.clamp( DirectionOfMovement.Z / Humanoid.WalkSpeed, 0.01, 1 ) )
	local Right = math.abs( math.clamp( DirectionOfMovement.X / Humanoid.WalkSpeed, 0.01, 1 ) )
	local Left = math.abs( math.clamp( DirectionOfMovement.X / Humanoid.WalkSpeed, -1, -0.01 ) )

	local SpeedUnit = (DirectionOfMovement.Magnitude / Humanoid.WalkSpeed)

	local State = Humanoid:GetState()

	if DirectionOfMovement.Magnitude > 0.1 then
		if AnimationsTable.WalkForward.IsPlaying == false then
			AnimationsTable.WalkForward:Play( 0,0.01,0 )
			AnimationsTable.WalkRight:Play( 0,0.01,0  )
			AnimationsTable.WalkLeft:Play( 0,0.01,0  )
		end
			
		
	end

	if DirectionOfMovement.Z/Humanoid.WalkSpeed < 0.1 then

		AnimationsTable.WalkForward:AdjustWeight( Forward )
		AnimationsTable.WalkRight:AdjustWeight( Right )
		AnimationsTable.WalkLeft:AdjustWeight( Left )

		AnimationsTable.WalkForward:AdjustSpeed( SpeedUnit )
		AnimationsTable.WalkRight:AdjustSpeed( SpeedUnit )
		AnimationsTable.WalkLeft:AdjustSpeed( SpeedUnit )

		AnimationsTable.Idle:AdjustWeight(0.001)

	else

		AnimationsTable.WalkForward:AdjustWeight( Backwards )
		AnimationsTable.WalkRight:AdjustWeight( Left )
		AnimationsTable.WalkLeft:AdjustWeight( Right )

		AnimationsTable.WalkForward:AdjustSpeed( SpeedUnit * -1 )
		AnimationsTable.WalkRight:AdjustSpeed( SpeedUnit * -1 )
		AnimationsTable.WalkLeft:AdjustSpeed( SpeedUnit * -1 )

		AnimationsTable.Idle:AdjustWeight(0.001)

	end


	if DirectionOfMovement.Magnitude < 0.1 then
		AnimationsTable.Idle:AdjustWeight(1)
	end
		
	UserInputService.InputBegan:Connect(function(input:InputObject,Key)
		if input.KeyCode == Enum.KeyCode.C then
			CrouchIdleAnim:Play(stanceChangeTime)
			CrouchSounds:Play()
			if DirectionOfMovement.Magnitude > 0.1 then
				if AnimationsTable.WalkForward.IsPlaying == true or CrouchMoveAnim == false then
					CrouchMoveAnim:Play(stanceChangeTime)
				end
			end
			if DirectionOfMovement.Z/Humanoid.WalkSpeed < 0.1 then
				AnimationsTable.WalkForward = CrouchMoveAnim
				CrouchMoveAnim:Adjustspeed (SpeedUnit)
				CrouchMoveAnim:AdjustWeight (Forward)
			else
				CrouchMoveAnim:AdjustWeight (Backwards)
			end
			end 
	end)
	
	UserInputService.InputBegan:Connect(function(input:InputObject,Key)
		if input.KeyCode == Enum.KeyCode.X then
			CrouchMoveAnim:Stop()
			CrouchIdleAnim:Stop(stanceChangeTime)
			CrouchGetUp:Play()
		end
	end)
end)
1 Like

Could it be that the animation is looped?