How do I check what platform the player is standing on?

How do I check what Part a player is standing on? I want to make a block that gets the deleted once the player stands on it, I could easily do that with an OnTouched event but that would make it so the Part deletes itself when the player touches it instead of when the player stands on it.

2 Likes

You can have a raycast check with your touch event. So when the touch event for the part gets fired → get the player who touched the part → raycast from the players HumanoidRootPart straight down → if the raycast hits the part that means the player is standing on it, if the raycast doesn’t hit then the player just touched the part from the side or below.

4 Likes

Script to make it work:

(insert this into a server script inside the platform)
(also, you should give the solution to the @Ze_tsu as he was first)

--//Services
local Players = game:GetService("Players")

--//Variables 
local Part = script.Parent

--//Functions
local function FireRay(character)
	local rayOrigin = character.HumanoidRootPart.Position
	local rayDirection = Vector3.new(0, -100, 0)

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
	
	return raycastResult.Instance
end

Part.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if Humanoid then
		local RayInstance = FireRay(hit.Parent)
		
		if RayInstance == Part then
			print(hit.Parent.Name, "is standing on", script.Parent:GetFullName())
		end
	end
end)

The only real way to do this would be to send a raycast downwards to detect it.

I am too tired to write code examples for Raycasting so I’ll just give you the wiki page for workspace:Raycast

HOWEVER, Roblox clearly already has the code to do this because how else would FloorMaterial work HMMMMMMMMMMMM

Yea, I’ve been trying to find the script for it.

Thank you both very much, I’ll work with this to what I need.

1 Like

Its controlled by backend engine code. There is no Lua script that does this lol (the property is readonly)