I want to be able to detect the floor that a player is standing on.
The solution I came up with is by making a raycast that goes from the HumanoidRootPart downwards, and it works, but there’s one slight problem. When I stand on a ledge of a part, it doesn’t detect a floor, even though I’m standing.
repeat wait() until game.Players.LocalPlayer.Character
local rootpart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local floordetector = Instance.new("Part")
floordetector.Size = Vector3.new(1.95, 0.003, .95)
floordetector.Transparency = 0
floordetector.CanCollide = false
floordetector.Parent = workspace
game:GetService("RunService").RenderStepped:Connect(function()
floordetector.CFrame = rootpart.CFrame + rootpart.CFrame.UpVector * (-3 - humanoid.HipHeight)
local connection = floordetector.Touched:Connect(function() end)
local parts = {
unpack(floordetector:GetTouchingParts()),
}
connection:Disconnect()
for i, floor in parts do
if floor.CanCollide == true then
--code
break
end
end
end)
This was actually my second idea, but I didn’t bother saying it. I suggest using a weld instead of setting the CFrame of it every render step.
Also, you might need to connect an empty function to the Touched event of the floor detector, so GetTouchingParts can be the most reliable.
I don’t really know how to use welds so this was basically my only solutions, but I’d say that using a weld would work too. Also I did add a touched event because without it, it wouldn’t have worked.