How do I get a tool to give me the name a brick when I click on it?
I am trying to make an axe be able to chop down wood but I'm struggling to figure out how to make sure if it clicks on a tree.
This is what I tried.
01 | local playerName = script.Parent.Parent.Parent.Name |
02 | local Player = game.Players:WaitForChild(playerName) |
03 | local tool = script.Parent |
04 | local Mouse = Player:GetMouse() |
05 | local Character = Player.Character or Player.CharacterAdded:Wait() |
06 | local maxDistance = 300 |
07 | local BrickColor = BrickColor.new( "Really red" ) |
09 | local function onActivation() |
10 | local Ray = Ray.new(tool.Handle.CFrame.p, (Mouse.Hit.p - tool.Handle.CFrame.p).unit * maxDistance) |
11 | local Part, Position = workspace:FindPartOnRay(Ray, Character, false , true ) |
12 | local name = Part.Name |