Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Get terrain material from mouse.Target?

Asked by
Zeuxulaz 148
4 years ago

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

01while wait(1) do
02 
03    local p = game.Players.LocalPlayer
04    local m = p:GetMouse()
05 
06    if m.Target.Name == "Terrain" then
07 
08        print(m.Target) -- Here is where I want something like m.Target.TerrianMaterial
09 
10    else
11 
12        print(m.Target)
13 
14    end
15 
16end

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

Is this possible?

1
Cast a ray at m.Hit and check the material it returns Amiaa16 3227 — 4y
0
as far as i can tell this is the best way to do this ^ Warphi 51 — 4y
0
ok Zeuxulaz 148 — 4y
0
I'd cast a ray at m.Hit and check the mater u want return it Brady1290 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Ignore my previous post, this works.

This one does it every 2 seconds.

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

This one does it once:

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

Answer this question