How to get parts player is climbing on

how would I get the parts the player is climbing on??

is it possible to get the parts that the player is climbing on?
example: {truss}
or {part, part, part} since players can climb on to things that look like ladders

please explain more detail and please dont sound like a meme
your post should include more detail so others can help or people will ignore your topic

my caps lock is broken for a while idk why

1 Like

Hi, you can check the humanoid’s StateType and then use a raycast to get the part directly in front of them. I’ve attached code to check the StateType

Place this script in StarterCharacterScripts

local hum = script.Parent:WaitForChild('Humanoid')

hum.StateChanged:Connect(function()
	print(hum:GetState())
end)

Read more about this event here

1 Like

Hey there, let me give you some of my wisdom.

You can use HumanoidStateType like Barkus just demonstrated, Instead of printing the StateType we need to actually check if the player is climbing something, here is the code:

local hum = script.Parent:WaitForChild('Humanoid')

hum.StateChanged:Connect(function()
     if hum:GetState() == Enum.HumanoidStateType.Climbing then
-- player is climbing put code in here (raycast)
end
end)
1 Like

Also, Instead Of Raycast, Blockcast is probably a better option for getting a ladder since a raycast could go through or miss a ladder while a Blockcast might get the closest part without missing the rung. Would be nice if roblox detected Ladders with Humanoid.FloorMaterial as well though, or had a separate property for the humanoid similar to FloorMaterial but for ladders.

edit: ye blockcast seems to work ok. Here is some code i made for it:

game.Workspace.DescendantAdded:Connect(function(descendant)
	if descendant:IsA("Humanoid") then
		descendant.Climbing:Connect(function(speed)
			print("Climbing at a speed of: " .. speed .. " SPS")
			while descendant:GetState() == Enum.HumanoidStateType.Climbing do
				local Char:Model = descendant.Parent
				local HRP:BasePart = Char:WaitForChild("HumanoidRootPart",5)
				local RCP = RaycastParams.new()
				RCP.RespectCanCollide = true
				RCP.FilterDescendantsInstances = {Char}
				RCP.FilterType = Enum.RaycastFilterType.Exclude
				RCP.IgnoreWater = true
				local Cast = workspace:Blockcast(HRP:GetPivot(),Vector3.new(.5,6,0),HRP:GetPivot().LookVector,RCP)
				local ClimbingObject = Cast.Instance
				print("Currently Climbing On: " , ClimbingObject)
				task.wait()
			end
		end)
	end
end)

The Only issue here is that it seems that climbing on something thin might not work but that should be fixable by moving the blockcast start pos slightly backwards.

Edit 2: Quick Update. Fixed Some Issues with my previous code And Added Commenting. Here Ya Go:

game.Workspace.DescendantAdded:Connect(function(descendant) -- This is just how i got the humanoid in this case, i would not recommend actually using this, you should probably use a specific humanoid instead
	if descendant:IsA("Humanoid") then -- checking if the descendant is a humanoid
		descendant.Climbing:Connect(function(speed) -- check for if the humanoid started climbing or changed climbing speed
			print("Climbing at a speed of: " .. speed .. " SPS") -- print climbing speed
			while descendant:GetState() == Enum.HumanoidStateType.Climbing do -- loop that runs while the humanoid is climbing.
				local Char:Model = descendant.Parent -- get character. you probably used a different method and already have the character, so use that instead.
				local HRP:BasePart = Char:WaitForChild("HumanoidRootPart",5) -- get HumanoidRootPart
				local RCP = RaycastParams.new() -- RaycastParams
				RCP.RespectCanCollide = true -- Most likely cant climb on CanCollide False Objects so ignore them.
				RCP.FilterDescendantsInstances = {Char} -- Ignore the Character
				RCP.FilterType = Enum.RaycastFilterType.Exclude -- Set RCP to Ignore
				RCP.IgnoreWater = true -- Ignore water as well, you probably cant climb on it.
				--local CastPos = HRP:GetPivot().Position + Vector3.new(0,0,.5)*(-HRP:GetPivot().LookVector) -- Move the cast slightly backwards if you want
				--local NewCFrame = CFrame.new(CastPos) * HRP:GetPivot().Rotation -- Turns CastPos into a CFrame.
				--[[
				Quick Note: 
				
				The Part Size I decided On And Recommend Is Vector3.new(.1,2,0).
				 - I set X to .1 In Order To get Thin Ladders And not the Objects Or walls that May Surround them.
				 - I set Y to 2 Because that is the Size of the HumanoidRootPart and also A good Size That can Get The Ladder the Player is Climbing On Without Getting Floors Or Ceilings Jutting Out Above And Below
				 - I set Z to 0 In Order To make sure the Blockcast doesn't start on the other side of the ladder.
				--]]
				local Cast = workspace:Blockcast(HRP:GetPivot(),Vector3.new(.1,2,0),HRP:GetPivot().LookVector*2,RCP) -- Do The Blockcast
				if Cast then -- Make Sure Cast Exists. You could also do "if not Cast then continue end"
					local ClimbingObject = Cast.Instance -- Object You Are Probably Climbing on. Curved or Jutting Out Objects Around the Ladder May Interfere.
					print("Currently Climbing On: " , ClimbingObject) -- Print the Object.
				end
				task.wait() -- Slight Wait so you dont crash studio like I accidentally did by forgetting this.
			end
		end)
	end
end)

Also, This works fine for thin parts, you just need to worry more about parts that may jut out above, below, around, or through your ladder.

Oh, And, I Noticed I Used an odd Method of getting the Humanoid By accident because I was testing something else, so I recommend probably using a different more normal way.

1 Like