Mouse.Target is always nil

Hello i am trying to achieve Click detecting on parts without using Click Detector but when i play test this code Target is always nil and isnt changing

can smn tell me why this happens and how can make my mouse tell the target

-- This is an example Lua code block

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Target = Mouse.Target

Mouse.Move:Connect(function()

	print(Target)

end)
1 Like

Assuming this is a local script (If it’s not, then you can’t access the player mouse from a localscript):

You are saving the target as a variable at the start, meaning that when you print Target you’re just printing your initial changed variable which is static. When you save it as a variable, you’re not saving the changing part of it. If you would like to print the target, just print Mouse.Target in your Mouse.Move function.

1 Like

The issue is that you are using the same target from the beginning of the script. You should set target each time the mouse moves and print it afterwards.

2 Likes

My bad I didn’t see u said it first.

3 Likes

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