Ad
Log in to vote
0

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

Asked by 4 days ago
Edited 3 days ago

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

Log in to vote
0
Answered by 3 days ago

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

Ad
Log in to vote
-1
Answered by
FirezDevv 147
4 days ago
Edited 4 days ago

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)
0
It's a server script. How do I use this? squidiskool 185 — 4d
0
Edited, there you go this will work with the server script FirezDevv 147 — 4d
0
I got the error: Error: (11,2) Syntax error: Incomplete statement: expected assignment or a function call squidiskool 185 — 4d
0
Workspace.UnityEngine.Texture2D.Script:12: attempt to index nil with 'Target' squidiskool 185 — 4d
View all comments (5 more)
0
Workspace.UnityEngine.Texture2D.Script:15: attempt to index nil with 'GetMouse' squidiskool 185 — 4d
0
uhh squidiskool 185 — 4d
0
Wrong signal, 'MouseButton1Down', it's 'Button1Down'. Please fix that one-line, it's atrocious and should never, ever, be written again. Ziffixture 6529 — 4d
0
that doesn't help squidiskool 185 — 4d
0
When it's unequipped, the tool is in a folder called "Backpack". squidiskool 185 — 3d

Answer this question