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

How do I make this tool select the part that the player clicked on?

Hello, I'm making btools. I'm wondering how do you get the part that the player clicked on? I want it so that when you click on the part, a decal appears on the part you clicked.

local tool = script.Parent

local function Texture2D(point)
	local Texture2D = Instance.new("Decal")
	Texture2D.Texture = "rbxassetid://6423847544"
	Texture2D.Face = "Top"
	Texture2D.Parent = point
end

local function onActivated()
	local human = tool.Parent.Humanoid
	Texture2D(human.TargetPoint) 
end

tool.Activated:Connect(onActivated)

Update: @FirezDevv supplied me a script, but it doesn't work and he just suddenly left when I reported an error. Can anybody help? It's a server script is parented to a tool, and the error I get is "Workspace.UnityEngine.Texture2D.Script:15: attempt to index nil with 'GetMouse'".

local tool = script.Parent

local function Texture2D(point)
    local Texture2D = Instance.new("Decal")
    Texture2D.Texture = "rbxassetid://6423847544"
    Texture2D.Face = "Top"
    Texture2D.Parent = point
end

local function onActivated(mouseT)
    local human = tool.Parent.Humanoid
    Texture2D(mouseT) 
end

game.Players:FindFirstChild(tool.Parent.Name):GetMouse().MouseButton1Down:Connect(function()
onActivated(game.Players:FindFirstChild(tool.Parent.Name):GetMouse().Target)
end)

2 answers

I fixed it myself by using a remoteevent with a localscript and a server script.

Alright I will rewrite this

Since you are using a server script the tool is most likely in the character

If the script's parent is the tool then this will work, but if it is in more objects just put more .Parent

local tool = script.Parent

local function Texture2D(point)
    local Texture2D = Instance.new("Decal")
    Texture2D.Texture = "rbxassetid://6423847544"
    Texture2D.Face = "Top"
    Texture2D.Parent = point
end

local function onActivated(mouseT)
    local human = tool.Parent.Humanoid
    Texture2D(mouseT) 
end

game.Players:FindFirstChild(tool.Parent.Name):GetMouse().MouseButton1Down:Connect(function()
onActivated(game.Players:FindFirstChild(tool.Parent.Name):GetMouse().Target)
end)

9 comments

0

It's a server script. How do I use this?

0

Edited, there you go this will work with the server script

0

I got the error: Error: (11,2) Syntax error: Incomplete statement: expected assignment or a function call

0

Workspace.UnityEngine.Texture2D.Script:12: attempt to index nil with 'Target'

0

Workspace.UnityEngine.Texture2D.Script:15: attempt to index nil with 'GetMouse'

0

uhh

0

Wrong signal, 'MouseButton1Down', it's 'Button1Down'. Please fix that one-line, it's atrocious and should never, ever, be written again.

0

that doesn't help

0

When it's unequipped, the tool is in a folder called "Backpack".

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