So I'm currently Experimenting with the Mouse and I've run into a bit of an error
Apologies if it's a bit hard to understand my question.
(LocalScript) :
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
function TestMouse ()
local Distance = (Mouse.Target.Position.magnitude - Player.Character.Torso.Position.magnitude)--Line 13
if Mouse.Target == nil then
print ("Not an Object;nil")
elseif Distance <= 10 and Mouse.Target ~= nil then
Mouse.Target.BrickColor = BrickColor.new("Bright red")
print ("Succesfully Changed BrickColor to Bright red")
elseif Distance >10 and Mouse.Target ~= nil then
print ("Distance = "..Distance)
end
end
Mouse.Button1Down:connect(TestMouse)
Basically whenever I try to click somewhere on the Skybox it doesn't print : "Not an Object;nil"
and gives me this error :
Players.Player.PlayerGui.MouseTest:13: attempt to index field 'Target' (a nil value)
The LocalScript works perfectly unless I click somewhere on the Skybox

1 comment
It's because you're trying to calculate Distance before checking if the mouse's target is nil or not.