Mouse.Target Breaking on Detecting the sky

So i want to get if the mouse’s target is a part or not, if it’s a part then i want a function to start.

The script works when i click and everything but as soon as i click in the sky / the air, the script breaks and can’t detect that the sky is a thing.

i have tried the Mouse.TargetFilter function but it doesn’t seem to do any different.

Code:

-- if Mouse.Target:IsA("Part") then

Error:

-- Players.martearo.Backpack.Item.LocalScript:24: attempt to index nil with 'IsA'

Any Help would be greatly appreciated

1 Like

Add an additional check to make sure Mouse.Target ~= nil.

8 Likes
if Mouse.Target.Parent == workspace and Mouse.Target:IsA("Part") then
1 Like

i have tried that before but sadly it didn’t work too

1 Like

You can also shoot a ray to the mouse lookvector for a better input but thats your decision.

it just gives you more options to do with the hit position and normal!

2 Likes