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):

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?

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.

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
Ad

Answer this question