How to detected if the mouse touch a child of a model?

How to detected if the mouse touch a child of a model ?

local Player = game.Players.LocalPlayer
local Cursor = game:GetService("MouseService")
local Model = workspace.R6

repeat wait() until Model

while wait() do
	
	local Mouse = game.Players.LocalPlayer:GetMouse()
	
	if Mouse.Target == Model then
		
		print(Mouse.Target)
		
	end
	
end

my script don’t work

2 Likes

Can you show me the output, please?

1 Like

nothing appears even if I move my mouse over it

1 Like

if Mouse.Target:IsAncestorOf(Model) then

1 Like

Players.pageotkillian1.PlayerScripts.LocalScript:11: attempt to index nil with ‘IsAncestorOf’

In the line where the mouse variable is, do:

local Mouse = Player:GetMouse()

Otherwise, your first variable is basically useless.

Also not to mention, the Cursor variable also serves no purpose (unless you’re planning to use it later on).

Thanks, but it doesn’t solve my problem

1 Like

check if Mouse.Target exists first

if Mouse.Target and Mouse.Target:IsAncestorOf(Model) then

Yes it exists and it hasn’t changed a thing

then try this

if Mouse.Target and Mouse.Target.Parent == Model then
1 Like

Thanks for your help and also @AlexPalex178

3 Likes

Final script

local Player = game.Players.LocalPlayer
local Model = workspace.R6

repeat wait() until Model

while wait() do
	
	local Mouse = Player:GetMouse()
		
		if Mouse.Target and Mouse.Target.Parent == Model then

			print(Mouse.Target)

		end
	
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.