Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Get terrain material from mouse.Target?

Here's the code I did (it's in a LocalScript in StarterPlayerScripts):

while wait(1) do
	
	local p = game.Players.LocalPlayer
	local m = p:GetMouse()
	
	if m.Target.Name == "Terrain" then
		
		print(m.Target) -- Here is where I want something like m.Target.TerrianMaterial
		
	else
	
		print(m.Target)
		
	end
	
end

I want it to print "Stone" or "Mud" if the mouse target is pointing to "Stone" or "Mud" (just an example).

Is this possible?

4 comments

1

Cast a ray at m.Hit and check the material it returns

0

as far as i can tell this is the best way to do this ^

0

ok

0

I'd cast a ray at m.Hit and check the mater u want return it

1 answer

Ignore my previous post, this works.

This one does it every 2 seconds.

local RunService = game:GetService("RunService")
local p = game.Players.LocalPlayer
local m = p:GetMouse()
while true do 
wait(2) --change this to anything you like
if m.Target and m.Target:IsA("BasePart") then
   print(m.Target.Material)
	end
end

This one does it once:

local RunService = game:GetService("RunService")
local p = game.Players.LocalPlayer
local m = p:GetMouse()
wait(2) --change this to anything you like
if m.Target and m.Target:IsA("BasePart") then
   print(m.Target.Material)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.