Crouch floating when equip tool

I think I know how to fix that problem, show me the new crouch script please

local TweenService = game:GetService(“TweenService”)
local Humanoid = game:GetService(“Players”).LocalPlayer.Character:WaitForChild(“Humanoid”)
local HumanoidRootPart = game:GetService(“Players”).LocalPlayer.Character:WaitForChild(“HumanoidRootPart”)

local CrouchAnimation = script.CrouchAnimation
local CrouchTrack = Humanoid:LoadAnimation(CrouchAnimation)

local CameraInfo = TweenInfo.new(
0.3,
Enum.EasingStyle.Quint,
Enum.EasingDirection.Out,
0,
false,
0
)

local CrouchedGoal = {CameraOffset = Vector3.new(0,-1.75,0)}
local UncrouchedGoal = {CameraOffset = Vector3.new(0,0,0)}

local CrouchedTween = TweenService:Create(Humanoid, CameraInfo, CrouchedGoal)
local UncrouchedTween = TweenService:Create(Humanoid, CameraInfo, UncrouchedGoal)

local inCrouch = false

local function Crouch()
if inCrouch == false then
inCrouch = true
CrouchedTween:Play()
Humanoid.WalkSpeed = 8
CrouchTrack:Play()

	HumanoidRootPart.CanCollide = false
	
else
	inCrouch = false
	UncrouchedTween:Play()
	Humanoid.WalkSpeed = 16
	CrouchTrack:Stop()
	
	HumanoidRootPart.CanCollide = true
	
end

end

game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
Crouch()
end
end)

Blockquote

You’ll need to use the gameProcessedEvent argument in the InputBegan event like so:

local TweenService = game:GetService("TweenService")
local Humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local HumanoidRootPart = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")

local CrouchAnimation = script.CrouchAnimation
local CrouchTrack = Humanoid:LoadAnimation(CrouchAnimation)

local CameraInfo = TweenInfo.new(
0.3,
Enum.EasingStyle.Quint,
Enum.EasingDirection.Out,
0,
false,
0
)

local CrouchedGoal = {CameraOffset = Vector3.new(0,-1.75,0)}
local UncrouchedGoal = {CameraOffset = Vector3.new(0,0,0)}

local CrouchedTween = TweenService:Create(Humanoid, CameraInfo, CrouchedGoal)
local UncrouchedTween = TweenService:Create(Humanoid, CameraInfo, UncrouchedGoal)

local inCrouch = false

local function Crouch()
if inCrouch == false then
inCrouch = true
CrouchedTween:Play()
Humanoid.WalkSpeed = 8
CrouchTrack:Play()

	HumanoidRootPart.CanCollide = false
	
else
	inCrouch = false
	UncrouchedTween:Play()
	Humanoid.WalkSpeed = 16
	CrouchTrack:Stop()
	
	HumanoidRootPart.CanCollide = true
	
end
end

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

if input.KeyCode == Enum.KeyCode.C then
Crouch()
end
end)

Edit: @DANIEEELLLL13 underlines should be fixed now, it was the same issue as before with the quotes

1 Like

Thank u so much now i have finally fix this and now im able to crouch
with gun as well

u deserved an medals

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.