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

How to access Mouse.Target parent?

Hi guys, I need to get a parent of the part targeted by the mouse, I tried with something like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function myFunction()
	if tostring(mouse.Target) == "MyBrick" then
		local instance = mouse.Target.Parent:FindFirstChild("InstanceID")
		instance.Value = 15;
	end
end

But that wont work, why?

1 answer

Not too sure why that didn't work, but gonna try to put my hand on it:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function myFunction()
	if mouse.Target then
		if mouse.Target.Name == "MyBrick" then
			local instance = mouse.Target.Parent:FindFirstChild("InstanceID")
			instance.Value = 15;
		end
	end
end

Also I hope you do call that function somewhere.

3 comments

0

Let's see

0

Didn't work, I don't know why

0

Do you ever call that function? If you want that to happen when ever you click, you have to add this at end: mouse.Button1Down:connect(myFunction)

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