Self explanatory. I made a crouch script and InputBegan is not firing for my input (C) for some reason
-- This is the pc input handler.
wait(1.25);
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local Player = Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local CrouchKey = Enum.KeyCode.C
local Deb = false
-- Checks if Humanoid is Alive.
local function CheckAlive()
local Hum = Character:FindFirstChild("Humanoid")
local Head = Character:FindFirstChild("Head")
local HumanRoot = Character:FindFirstChild("HumanoidRootPart")
if Hum and Hum.Health > 0 and Head and HumanRoot then
return true
else
return false
end
end
-- Checks if head is in the way
local function CheckHead()
if not CheckAlive() then return end
local rayOrigin = Character.Head.Position
local rayDirection = Vector3.new(0, 2, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Transparency == 0 then
return false
else
return true
end
else
return true
end
end
-- Input begans, crouch idle
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.C and CheckAlive() == true then
print("C")
if not Deb then
Deb = true
local CrouchIdle = Character:WaitForChild("Humanoid"):LoadAnimation(script.CrouchIdle)
local Animate = Character:WaitForChild("Animate")
CrouchIdle:Play()
Animate.walk.WalkAnim.AnimationId = script.CrouchWalk.AnimationId
game:GetService("TweenService"):Create(Character:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 0.3}):Play()
Deb = false
end
end
end)
-- Input ends
UIS.InputEnded:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.C and CheckAlive() == true then
print("C end")
if CheckHead() then
local Animate = Character:WaitForChild("Animate")
local CrouchIdle = Character:WaitForChild("Humanoid"):LoadAnimation(script.CrouchIdle)
CrouchIdle:Stop()
Animate.walk.WalkAnim.AnimationId = "rbxassetid://10898889275"
game:GetService("TweenService"):Create(Character:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 2}):Play()
end
end
end)
Just tested it out on my own in studio, and it works well.
Could you re-check if the scripts are actually being putted into your character upon loading?
One - Instead repeat wait() until Player.Character
you can just have local Character = Player.Character or Player.CharacterAdded:Wait()
Two - CrouchKey on top of the script is not being used so make sure
to replace it in the if statement like this if input.KeyCode == CrouchKey and CheckAlive() == true then end
Three - You can called tween service on top of the script instead of getting the service each time or and make the Crouch Tween on top of the script instead of creating the tween
Try, Loading the Animation Inside of the Humanoid.Animator if it’s r15 (Not really sure if r6 has it)
I tried Humanoid.Animator and it didn’t work well so I used the depricated version since it always worked for me. I will change it back and try to fix it. I tried Player.CharacterAdded:Wait() and it yielded the code so I just used to unoptimal version.
-- Services
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CrouchKey = Enum.KeyCode.C
local Deb = false
-- Checks if Humanoid is Alive.
local function CheckAlive()
local Hum = Character:FindFirstChild("Humanoid")
local Head = Character:FindFirstChild("Head")
local HumanRoot = Character:FindFirstChild("HumanoidRootPart")
if Hum and Hum.Health > 0 and Head and HumanRoot then
return true
else
return false
end
end
-- Checks if head is in the way
local function CheckHead()
if not CheckAlive() then return end
local rayOrigin = Character.Head.Position
local rayDirection = Vector3.new(0, 2, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
if hitPart.Transparency == 0 then
return false
else
return true
end
else
return true
end
end
-- Input begans, crouch idle
UIS.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == CrouchKey and CheckAlive() == true then
print("C")
if not Deb then
Deb = true
--local CrouchIdle = Character:WaitForChild("Humanoid"):LoadAnimation(script.CrouchIdle)
--local Animate = Character:WaitForChild("Animate")
--CrouchIdle:Play()
--Animate.walk.WalkAnim.AnimationId = script.CrouchWalk.AnimationId
TweenService:Create(Character:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 0.3}):Play()
Deb = false
end
end
end)
-- Input ends
UIS.InputEnded:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.KeyCode == CrouchKey and CheckAlive() == true then
print("C end")
if CheckHead() then
--local Animate = Character:WaitForChild("Animate")
--local CrouchIdle = Character:WaitForChild("Humanoid"):LoadAnimation(script.CrouchIdle)
--CrouchIdle:Stop()
--Animate.walk.WalkAnim.AnimationId = "rbxassetid://10898889275"
TweenService:Create(Character:FindFirstChild("Humanoid"), TweenInfo.new(0.2), {HipHeight = 2}):Play()
end
end
end)
This worked just fine for me without the animations of course they are comment out since i don’t have the animations I gave it try the inputBegan and inputEnded works just fine for me