Crouch script, needs some adjustments. Does not work as intended with tools equipped?

Hello, I’m making a game like Criminality. At the moment, I’m working on the crouch mechanic but it needs some adjustments and it really should work better. I’m new to animations and animation priorities. So if you guys could help it would mean the world!

So right now my problem is:

When I hold C, the player crouches, when I start moving the player stops crouching and I need to press C *while walking if I want to walk-crouch.

The other problem I have is when I have a tool equipped the animation is played off the ground as if the tool is anchored. (I’m not sure if I need to set the hip height.)

Here is when I try to walk WHILE in crouch. And also crouch when I’m already walking.

Here is when I have a tool equipped when trying to crouch.

Overall the animation is stuttery, and also stops when I’m moving my camera around. Any help would be appreciated. Thanks!

I will provide the code if needed. :smiley:

1 Like

Can we see the code? You should always provide the code when asking for help so we can help you straight away rather than having to ask for it.

local uis = game:GetService("UserInputService")

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() or script.Parent
local hum = char:WaitForChild("Humanoid")

local sprintAnim = script:WaitForChild("Sprint")
local sprintTrack = hum:LoadAnimation(sprintAnim)

local crouchWalk = hum:LoadAnimation(script:WaitForChild("CrouchWalk"))
local crouch = hum:LoadAnimation(script:WaitForChild("CrouchIdle"))

local running = false
local crouching = false

--Sprint--

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and hum.MoveDirection.Magnitude > 0 then
		player.Character:WaitForChild("Humanoid").WalkSpeed = 30
		sprintTrack:Play()
		running = true
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		player.Character:WaitForChild("Humanoid").WalkSpeed = 10
		sprintTrack:Stop()
		running = false
	end
end)

--Sprint--

--Crouch--

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C and running == false then
		if hum.MoveDirection.Magnitude == 0 then
		crouch:Play()
		hum.WalkSpeed = 6
		crouching = true
	elseif hum.MoveDirection.Magnitude > 0 then
		crouchWalk:Play()
		hum.WalkSpeed = 6
		crouching = true
		end
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		crouchWalk:Stop()
		crouch:Stop()
		hum.WalkSpeed = 10
		crouching = false
	elseif running == true then
		hum.WalkSpeed = 30
	end
end)

--Crouch--


hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if hum.MoveDirection.Magnitude == 0 then
		sprintTrack:Stop()
		player.Character:WaitForChild("Humanoid").WalkSpeed = 10
	elseif hum.MoveDirection.Magnitude > 0 and crouching == true then
		crouchWalk:Play()
	end
end)

Here is the code.

I provided the code now. Hopefully you can help.

I think this is due to how the tool is made, maybe try messing with anchoring and un anochoring certain parts of it.

Signed.
Kieranl29 Founder of D&R Studio and Dev forum helpers

Please stop posting your recruitment topic as your “signature”. It isn’t cool, just advertising. It actually draws people AWAY from it, so I see no benefit.

1 Like

Hows this, you can just get a life and stop complaining. It is not turn-offable, Just let people be.


Signed.
Kieranl29 Founder of D&R Studio and Dev forum helpers

It’s not the tool, I also tried another self-made tool. The result is the same.

If I’m correct, just remove the “Tool none” animation from your humanoid.