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

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.

local playerName = script.Parent.Parent.Parent.Name
local Player = game.Players:WaitForChild(playerName)
local tool = script.Parent
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local maxDistance = 300 
local BrickColor = BrickColor.new("Really red") 
 
local function onActivation()
	local Ray = Ray.new(tool.Handle.CFrame.p, (Mouse.Hit.p - tool.Handle.CFrame.p).unit * maxDistance)
	local Part, Position = workspace:FindPartOnRay(Ray, Character, false, true)
	local name = Part.Name
	print(name)
end

3 comments

0

What is script.Parent.Parent.Parent

0

um you can just get the mouse.Target from the client

0

@incapaz, first parent is tool, second parent is backpack, third parent is player.

1 answer

✓ Accepted answer

You can basically put a value on a tree that its name is "IsTree" and check if it's there.

1 comment

0

Thats not what im concerned about. In the script above I can't get the Part.Name, how do I do that?

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