Crouch floating when equip tool

Well there was a point in time where I wasn’t a good scripter as well, but by practice, research and experimentation I learnt what I know today

Im just in needed a help of way to fix this script but ty for advice

1 Like

I’m not quite sure if this is a script problem because the common problem people when making tools is they forgot to unAnchor and unColide the part in their tools :wink:

1 Like

All my tools is unachor ad uncolide

1 Like

See if changing the Humanoid’s HipHeight solves the problem:

local Player = game:GetService("Players").LocalPlayer
local Values = Player:WaitForChild("Values")
local Character = script.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("CROUCH")
local Animations = script:WaitForChild("Animations")
local Crouch = false
local Walking = true
local PlayingWalk = false
local AnimationsTracks = {}

local defaultHipHeight = Humanoid.HipHeight

module.Crouch = function (self)
	Crouch = not Crouch

	if Crouch then
		AnimationsTracks["Idle"] = Humanoid:LoadAnimation(Animations:WaitForChild("Crouch"))

		AnimationsTracks["Idle"].Priority = Enum.AnimationPriority.Idle

		if AnimationsTracks["Idle"] then
			AnimationsTracks["Idle"]:Play()
			Remote:FireServer()
		end

		Humanoid.HipHeight = 1 -- You might need to change this value, so try different ones and see if one works

		RunService.RenderStepped:Connect(function()
			if Crouch then
				local MoveDirection = Humanoid.MoveDirection

				if MoveDirection.Magnitude > 0 then
					Walking = true
				else
					Walking = false
				end
			end
		end)
	else
		Humanoid.HipHeight = defaultHipHeight

		if AnimationsTracks["Idle"] then
			AnimationsTracks["Idle"]:Stop()

			Remote:FireServer()
		end
	end
end

module.Init = function ()
	local self = setmetatable({},  {
		__index = module
	})

	UserInputService.InputBegan:Connect(function(Input, processed)
		if processed then
			return
		end
		
		if Input.KeyCode == Enum.KeyCode.C then
			self:Crouch()
		end
	end)

	return self
end

module.Init()

If it doesn’t work then unfortunately I don’t think I can continue helping you with this problem, but I do wish you luck in getting it solved

image
The console give me this type of error blue thingy idk why

Nope it didnt work the script when im trying to Press C nothing work

That’s because you haven’t created the module table inside of your script by doing local module = {} at the top

which line if u dont mind sorry for asking

1 Like

It should work if you add it in line 15

image
correct?

Yes but don’t do local module.Crouch afterwards else you’ll get the red underline error where the dot is, module.Crouch is correct without the local


image

How does the whole script look like now?

Normal
No red line
No blue line

I mean I’ll need to see the code again for the whole script the way it is now please so I can see why the Crouch function isn’t being found

local Player = game:GetService(“Players”).LocalPlayer
local Values = Player:WaitForChild(“Values”)
local Character = script.Parent
local Humanoid = Character:FindFirstChildOfClass(“Humanoid”)
local RunService = game:GetService(“RunService”)
local UserInputService = game:GetService(“UserInputService”)
local Remote = game:GetService(“ReplicatedStorage”):WaitForChild(“Remotes”):WaitForChild(“CROUCH”)
local Animations = script:WaitForChild(“Animations”)
local Crouch = false
local Walking = true
local PlayingWalk = false
local AnimationsTracks = {}

local defaultHipHeight = Humanoid.HipHeight

local module = {}

local moduleCrouch = function (self)
Crouch = not Crouch

if Crouch then
AnimationsTracks[“Idle”] = Humanoid:LoadAnimation(Animations:WaitForChild(“Crouch”))

  AnimationsTracks["Idle"].Priority = Enum.AnimationPriority.Idle

  if AnimationsTracks["Idle"] then
  	AnimationsTracks["Idle"]:Play()
  	Remote:FireServer()
  end

  Humanoid.HipHeight = 1 -- You might need to change this value, so try different ones and see if one works

  RunService.RenderStepped:Connect(function()
  	if Crouch then
  		local MoveDirection = Humanoid.MoveDirection

  		if MoveDirection.Magnitude > 0 then
  			Walking = true
  		else
  			Walking = false
  		end
  	end
  end)

else
Humanoid.HipHeight = defaultHipHeight

  if AnimationsTracks["Idle"] then
  	AnimationsTracks["Idle"]:Stop()

  	Remote:FireServer()
  end

end
end

module.Init = function ()
local self = setmetatable({}, {
__index = module
})

UserInputService.InputBegan:Connect(function(Input, processed)
if processed then
return
end

  if Input.KeyCode == Enum.KeyCode.C then
  	self:Crouch()
  end

end)

return self
end

module.Init()

This is what you’ll need to do:

local Player = game:GetService("Players").LocalPlayer
local Values = Player:WaitForChild("Values")
local Character = script.Parent
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("CROUCH")
local Animations = script:WaitForChild("Animations")
local Crouch = false
local Walking = true
local PlayingWalk = false
local AnimationsTracks = {}

local defaultHipHeight = Humanoid.HipHeight

local module = {}

module.Crouch = function (self)
	Crouch = not Crouch

	if Crouch then
		AnimationsTracks["Idle"] = Humanoid:LoadAnimation(Animations:WaitForChild("Crouch"))

		AnimationsTracks["Idle"].Priority = Enum.AnimationPriority.Idle

		if AnimationsTracks["Idle"] then
			AnimationsTracks["Idle"]:Play()
			Remote:FireServer()
		end

		Humanoid.HipHeight = 1 -- You might need to change this value, so try different ones and see if one works

		RunService.RenderStepped:Connect(function()
			if Crouch then
				local MoveDirection = Humanoid.MoveDirection

				if MoveDirection.Magnitude > 0 then
					Walking = true
				else
					Walking = false
				end
			end
		end)
	else
		Humanoid.HipHeight = defaultHipHeight

		if AnimationsTracks["Idle"] then
			AnimationsTracks["Idle"]:Stop()

			Remote:FireServer()
		end
	end
end

module.Init = function ()
	local self = setmetatable({},  {
		__index = module
	})

	UserInputService.InputBegan:Connect(function(Input, processed)
		if processed then
			return
		end
		
		if Input.KeyCode == Enum.KeyCode.C then
			self:Crouch()
		end
	end)

	return self
end

module.Init()

Edit: @DANIEEELLLL13 It should work now without the red underlines

Nope it didnt work either
the console show nothing

i have found a free script crouch system from youtube
but the only problem is when i type C in the chat
it keep me crouching