How caan i make my character cant uncrouch while under a part

like as i said on the title want to the localplayer cant unchrouch while under a part ive tried touched function but it was buggy anddoesnt work properly (when under a part and went to the another part thats the same height it detects as untouched etc.)
so how can i do it

1 Like

raycast above the character. if there is a part close to the character, don’t uncrounch.

yo bro so ive trying the raycast method but it just prints under a part and i guess its collisioning with my own character how can i exclude it with all models that include humanoids

local raydirection = Vector3.new(0,1,0)

RunService.Heartbeat:Connect(function()
	local rayresult = workspace:Raycast(CrouchBox.Position, raydirection)
	if rayresult then
		if not rayresult.Parent.Humanoid then
			IsUnderAPart = true
			print("under a part!")
		else
			IsUnderAPart = false
			print("not under a part!")
		end
	end
end)

local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
local rayresult = workspace:Raycast(CrouchBox.Position, raydirection, params)

oohhhh i get it now so params like the setting you want to include to the raycst thanks bro

yo bro i got a question again so if i do iv pair to the humanoid.parents in the workspace can i add it to exclude sorry im new to raycast

You forgot to add Length to your direction, that’s why it doesn’t work.

local raydirection = Vector3.new(0,1,0)

RunService.Heartbeat:Connect(function()
	local rayresult = workspace:Raycast(CrouchBox.Position, raydirection * 10)
	if rayresult then
		if not rayresult.Parent.Humanoid then
			IsUnderAPart = true
			print("under a part!")
		else
			IsUnderAPart = false
			print("not under a part!")
		end
	end
end)
1 Like

hm but 10 block isn bit too much? im making a backrooms game and it will pierce thourgh the eiling and make the sme error i guess

What’s the position of your Crouchbox to be exact? is it in the same position as HumanoidRootPart?

kinda lower like quarter of it

yo bro it worked with my local charaacter but i need it to exclude all models that include a humanoid is there any way to make it?

do you have rigs on your game that has a humanoid besides players?

im not but im gonna add monster ect that has humanoids

If so make a folder that contains both the Players and the Monsters etc. and add them to the raycast params filter like this:

local params = RaycastParams.new()
params.FilterDescendantsInstances = {character, Characters}
params.FilterType = Enum.RaycastFilterType.Exclude
local rayresult = workspace:Raycast(CrouchBox.Position, raydirection, params)

the “Characters” are the concept i said above

so how can i make the spawned players into the folder

When the Player’s Character spawns, put it into a folder
something like this:

game.Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Character)
		Character.Parent = workspace.PlayersFolder
	end)
end)
2 Likes

yo bro i figured it out hanks !

1 Like

Sorun deÄźil kardeĹź, ne mutlu tĂĽrkĂĽm diyene

1 Like