When your mouse isn’t pointing towards any object in the 3D space, mouse.Target returns nil.
You can simply check for this before proceeding further.
-- LocalScript
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
while task.wait(.009) do
local target = mouse.Target
if target then
local mouseattributes = target:GetAttributes()
print(mouseattributes)
end
end
Yup i was able to "sort of " fix the issue just not the part where it return nil, so thanks.
I also see that you have used GetService is there any difference from using game.players like I did? same thing for task.wait
About GetService(), it is generally a better coding practice to “get” services because it returns the Instance of the service by className, and not Name.
You’re able to rename certain services to a custom name and requiring them using GetService ensures your code won’t error regardless of if your service names are manipulated or modified in any form and that you get the correct service no matter what.
This applies to any “paths” that you’ll ever specify using the . operator, such as game.ReplicatedStorage.RemoteFolder.RemoteEvent for example.