Full LocalScript local UIS = game:GetService("UserInputService") local Crouching = false local Character = script.Parent local Humanoid = Character:WaitForChild("Humanoid") local Animation = script.CrouchAnimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if Crouching == false then Crouching = true LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play()
here is the script : local UIS = game:GetService("UserInputService") local UIS = game:GetService("UserInputService") local crouching = false local character = script.Parent local humanoid = character:WaitForChild("humanoid") local animation = script.crouchanimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if crouching == false then crouching = true loadedanimation = humanoid:loadedanimation(animation) loadedanimation:play()
There is something going wrong for me, it also happened when i did the sliding animation from one of your videos too, whenever i press the button, nothing happens .
You sure you didn't just misspell some parts? Cuz that's usually what happens when these kinds of problems happen, or maybe you used the wrong type of script or put it in the wrong place
Can you make a tutorial sequal to this video making it where when the player moves (while crouching) it plays a walking (crouch) animation? PLEASE I WANT MY GAME TO BE GOOD😭
great video! one question though; when a player is crouching under something, if they uncrouch while still under it then they'll stand up inside of it and get stuck, unless they crouch again. how could you modify the code to make it so that when a player is underneath something, they're unable to press the button until they have adequate room above them to do so? thanks!
I can't get my code to work local UIS = game:GetService("UserInputService") local Crouching = false local Character = script.Parent local Humanoid = Character:WaitForChild("Humanoid") local Animation = script.CrouchAnimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if Crouching == false then Crouching = true LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play()
try this local UIS = game:GetService("UserInputService") local Crouching = false local Character = script.Parent local Humanoid= Character:WaitForChild("Humanoid") local Animation = script.CrouchAnimation UIS.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.C then if Crouching == false then Crouching = true LoadedAnimation = Humanoid:LoadAnimation(Animation) LoadedAnimation:Play() Humanoid.HipHeight -= 1.5 Humanoid.WalkSpeed = 10 Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) else Crouching = false LoadedAnimation:Stop() Humanoid.HipHeight+=1.5 Humanoid.WalkSpeed = 23 Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true) end end end)
Here's a better script, when you crouch and your under something for example, your under a table, it stays in crouch for realism. Just make sure to put it in StarterPlayerScripts as a local script Here: -- Server Script (in ServerScriptService) local replicatedStorage = game:GetService("ReplicatedStorage") local crouchEvent = replicatedStorage:WaitForChild("CrouchEvent") local crouchHeight = 0.2 -- Adjust this for crouch depth local headClearance = 3 -- Adjust this for head clearance when standing up -- Function to check if there's space to stand up local function canStand(character) local headPosition = character.Head.Position local rayDirection = Vector3.new(0, headClearance, 0) local raycastParams = RaycastParams.new() raycastParams.FilterDescendantsInstances = {character} raycastParams.FilterType = Enum.RaycastFilterType.Blacklist local raycastResult = workspace:Raycast(headPosition, rayDirection, raycastParams) return raycastResult == nil -- If no obstacle above, it’s safe to stand end -- Handle crouch requests from client crouchEvent.OnServerEvent:Connect(function(player, isCrouching) local character = player.Character if character then local humanoid = character:FindFirstChild("Humanoid") if humanoid then -- Store the original HipHeight if it's not already stored if not humanoid:GetAttribute("OriginalHipHeight") then humanoid:SetAttribute("OriginalHipHeight", humanoid.HipHeight) end local originalHipHeight = humanoid:GetAttribute("OriginalHipHeight") if isCrouching then -- Set HipHeight to crouch height humanoid.HipHeight = crouchHeight else -- Only stand up if there’s space above the character if canStand(character) then humanoid.HipHeight = originalHipHeight end end end end end)
Full LocalScript
local UIS = game:GetService("UserInputService")
local Crouching = false
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script.CrouchAnimation
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
if Crouching == false then
Crouching = true
LoadedAnimation = Humanoid:LoadAnimation(Animation)
LoadedAnimation:Play()
Humanoid.HipHeight -= 1.2
Humanoid.WalkSpeed = 8
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
else
Crouching = false
LoadedAnimation:Stop()
Humanoid.HipHeight += 1.2
Humanoid.WalkSpeed = 16
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)
Thanks!
Your a Legend! Thanks!
thank you
W guy thanks
tysm !!
finally a tutoriall that isnt "USE MY FREE MODEL!!!"
Yessssss
THANK YOU soooo much ive checked every video and not one worked but this one did thank you
@@Teaflake I’m glad I helped!
THANK YOU SOOOOOOO MUCH BRO THIS IS SO USEFUL, IVE BEEN TRYING TO MAKE A HORROR GAME FOR MONTHS! (almost become a year)
@@deathtree0 I’m glad I helped!
Great video man, it was such a great video, from the very beginning
Thank you very much dear sire death who greatly does Roblox
YO HI DEATH I RANDOMLY SAW U IN AN MM2 SERVER NOW ON A COMMENT ON A RANDOM VIDEO LOL
@@TedMeister_w what a coincidence 😂😂 a pleasure to meet you too 🔥🔥
@@TedMeister_w yeeeee
Your videos are the best I found to start programming , keep it up man
Thanks ❤
@@devmelonroblox but tysm i appreciate it the script is usefull
W vid
Man ive been using your tutorials and they
Never upset anyone keep the good work! ^_^
Amazing video thank you so much you deserve more views +1 sub
Thank you cos I helped!
Glad*
Yoooo! Thank you so much this helped me a lot!
Glad it helped!
is there a way to make it where if u stop moving the anim stops but if u walk/crouch it will do that if ya know what i mean?
here is the script :
local UIS = game:GetService("UserInputService")
local UIS = game:GetService("UserInputService")
local crouching = false
local character = script.Parent
local humanoid = character:WaitForChild("humanoid")
local animation = script.crouchanimation
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
if crouching == false then
crouching = true
loadedanimation = humanoid:loadedanimation(animation)
loadedanimation:play()
humanoid.hipHeight -= 1.2
humanoid.walkspeed = 8
humanoid:setStateEnabled(Enum.HumanoidStateType,jumping, false)
else
crouching = false
loadedanimation:stop()
humanoid.hipHeight += 1.2
humanoid.walkspeed = 16
humanoid:setStateEnabled(Enum.HumanoidStateType,jumping, true)
end
end
end)
ty
@@CentaurTheNoob alright?
@@SussyAmogus2203 sussy
@@CentaurTheNoob sup?
The pfp is crazy-😭😭
Guys just remember if u code the animation with a R6 character u gotta change the gamesettings to R6 otherwise the animation wont play
for those who don't want to use "crouch = false", but rather invert the value, just put "crouch = not crouch" after the loop on line 13
There is something going wrong for me, it also happened when i did the sliding animation from one of your videos too, whenever i press the button, nothing happens
.
Same
same
You sure you didn't just misspell some parts? Cuz that's usually what happens when these kinds of problems happen, or maybe you used the wrong type of script or put it in the wrong place
Part of the issue could be because :loadAnimation() has been deprecated. It still works, but it's unreliable.
im here ;3
amazing
Ty for your com:3
Yw
Very Simple brooo very good
Thank you so much 🙂
Were do you do the whole thing Like witch Button is it or Plug in?
man bro this guy is a legend
Can you make a tutorial sequal to this video making it where when the player moves (while crouching) it plays a walking (crouch) animation? PLEASE I WANT MY GAME TO BE GOOD😭
W vid fr
yee thank you
i can crouch but when i walk while crouching its not looking good how do u fix it but without the walking problem this is the best one i found thx bro
Could you copy the script?
Second
Also W
W
What about a crouching walking animation?
@@LiamFurgason I might make a part 2
Does it still work because my animation is not working but the crouch is.
my character's entire lower half warps into the floor no matter the value i type in for hip height, anyone know how to fix?
LETS GOOOO W UPLOAD SCHEDULE
Fr
yeeee
great video! one question though;
when a player is crouching under something, if they uncrouch while still under it then they'll stand up inside of it and get stuck, unless they crouch again. how could you modify the code to make it so that when a player is underneath something, they're unable to press the button until they have adequate room above them to do so?
thanks!
hey can you help? whenever i uncrouch it wont stop crouching, the hipheight would return to normal but the animation wont stop
nevermind i fixed it :P
@@thefilipinoman21423 yo i have that same issue how did u fix it?
@@notnooby2118 copy the actual script lol, dont correct any orange lines
@@thefilipinoman21423 thanks
the animation doesnt play for me
but can you make walk crouch animation script
it doesn't work at all at ViewModel
could someone please help me? it wont work.
can you pls make a running system?
it wont play the animation for me
idk why it doesn't slowes me
it dosent play the animation
is this r15 or r6?
Any works
the animation does not work in the startercharacterscript cant add>:(
AND I STILL CAN RUN WITH SHIFT
its not working for me bruh
Hey devmelon pls help it didt work for me
im levitating bro idk what is happening
change the hipheight
ahahhaahhaah
it doesnt work for me
I'm on my parents account btw
why i cant :(
I can't get my code to work
local UIS = game:GetService("UserInputService")
local Crouching = false
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script.CrouchAnimation
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
if Crouching == false then
Crouching = true
LoadedAnimation = Humanoid:LoadAnimation(Animation)
LoadedAnimation:Play()
Humanoid.HipHeight -= 1.2
Humanoid.WalkSpeed = 7
Humanoid:SetStateEnable(Enum.HumanoidStateType.Jumping, false)
else
Crouching = false
LoadedAnimation = Humanoid:LoadAnimation(Animation)
LoadedAnimation:Stop()
Humanoid.HipHeight += 1.2
Humanoid.WalkSpeed = 16
Humanoid:SetStateEnable(Enum.HumanoidStateType.Jumping, true)
end
end
end)
try this
local UIS = game:GetService("UserInputService")
local Crouching = false
local Character = script.Parent
local Humanoid= Character:WaitForChild("Humanoid")
local Animation = script.CrouchAnimation
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
if Crouching == false then
Crouching = true
LoadedAnimation = Humanoid:LoadAnimation(Animation)
LoadedAnimation:Play()
Humanoid.HipHeight -= 1.5
Humanoid.WalkSpeed = 10
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
else
Crouching = false
LoadedAnimation:Stop()
Humanoid.HipHeight+=1.5
Humanoid.WalkSpeed = 23
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
end
end)
Mobile support?
I will make mobile buttons tut soon!
DevMelon shake🥴🥴🥴
what
It does not work
not working
Didn’t work
it doesn't work😡
broooo thats not working
Here's a better script, when you crouch and your under something for example, your under a table, it stays in crouch for realism.
Just make sure to put it in StarterPlayerScripts as a local script
Here:
-- Server Script (in ServerScriptService)
local replicatedStorage = game:GetService("ReplicatedStorage")
local crouchEvent = replicatedStorage:WaitForChild("CrouchEvent")
local crouchHeight = 0.2 -- Adjust this for crouch depth
local headClearance = 3 -- Adjust this for head clearance when standing up
-- Function to check if there's space to stand up
local function canStand(character)
local headPosition = character.Head.Position
local rayDirection = Vector3.new(0, headClearance, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(headPosition, rayDirection, raycastParams)
return raycastResult == nil -- If no obstacle above, it’s safe to stand
end
-- Handle crouch requests from client
crouchEvent.OnServerEvent:Connect(function(player, isCrouching)
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
-- Store the original HipHeight if it's not already stored
if not humanoid:GetAttribute("OriginalHipHeight") then
humanoid:SetAttribute("OriginalHipHeight", humanoid.HipHeight)
end
local originalHipHeight = humanoid:GetAttribute("OriginalHipHeight")
if isCrouching then
-- Set HipHeight to crouch height
humanoid.HipHeight = crouchHeight
else
-- Only stand up if there’s space above the character
if canStand(character) then
humanoid.HipHeight = originalHipHeight
end
end
end
end
end)
Ay
ayyy
@@WalkingTaco187 hi BCG
Firist😂
Cool
Like always
It didnt work😢
Turn the action to movement
@@Faizal-rv9mu hey how do i do that
Can you add me?
DIDNT EVEN WORK
The animation wont play?