Just like Humanoid.Floor.Material, I need to get the color of the floor too. How would I do that?
I believe you can’t get the part the player is standing on this way.
However, you can used the Humanoid’s Touched event which detects what part has touched the Humanoid’s limb. This may not be exactly efficient because it fires constantly when the player is moving instead at a given time.
This is a rough example for R6 characters:
Player.Character.Humanoid.Touched:Connect(function(PartHit, LimbPart)
if LimbPart == "Left Leg" or "Right Leg" then
-- Do whatever you want to do
end
end)
Raycasting.
You can cast a ray downwards from the humanoidrootpart and get a part’s color.
I can write up a demonstration script when I get home for you.
More precisely, downcasting. Don’t worry, I got you. I think.
local Ray = Ray.new(RootPart.Position, Vector3.new(0, -3, 0))
local FloorPart = workspace:FindPartOnRay(Ray, IgnoreDescendantsObject)
For a reference on how I organised the variables, see Ray datatype documentation. Essentially:
- First argument takes the origin, which I set to the RootPart’s position
- Second argument takes a directional vector, which I made 3 studs down
- Construct a ray using the above arguments, then pass it into a raycast method
(Happy anniversary on the DevForum)
The IgnoreDescendantsObject shows warning, what’s wrong with it?
You’re not supposed to type that out explicitly, you’re supposed to set an object. Like for example, you could replace it with “Character” (a variable that references the Character model).
You can put this in a local script in StarterPlayerScripts
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
while wait(1) do
local newRay = Ray.new(HumanoidRP.CFrame.p, Vector3.new(0,-1,0).unit * 10)
local Hit = game:GetService("Workspace"):FindPartOnRay(newRay, Character)
if Hit then
local HitBrickColor = Hit.BrickColor
local HitColor3 = Hit.Color
--print(HitBrickColor)
--print(HitColor3)
end
end
Hey! That worked but it keeps finding the legs of the character, how do I ignore the descendants of the character?
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
You could try this:
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
local IgnoreList = {}
table.insert(IgnoreList, Character)
while wait(1) do
local newRay = Ray.new(HumanoidRP.CFrame.p, Vector3.new(0,-1,0).unit * 10)
local Hit, position = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(newRay, IgnoreList)
if Hit then
local HitBrickColor = Hit.BrickColor
local HitColor3 = Hit.Color
--print(HitBrickColor)
--print(HitColor3)
end
end
Even though :FindPartOnRay
has an ignore parameter, it only allows one Instance to be ignored, not an array. This is why you’d use :FindPartOnRayWithIgnoreList
Actually it ignores that instance and all its descendants, so it shouldn’t interfere with the legs. (I’ve also tested my code before posting it here and it was working just fine.)