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