of     1   

CrustyCitation5
#183911247Thursday, February 18, 2016 11:58 PM GMT

function FetchThings() if Mouse.Target ~= nil then if Mouse.Target.ClassName == "Part" then end end end Mouse.Idle:connect(function() FetchThings() end) Mouse.Move:connect(function() FetchThings() end) FetchThings() will throw the error "attempt to index field 'Target' (a nil value)" when it checks for the ClassName. It sometimes happens, and sometimes not. I don't understand what triggers this and why it doesn't work with the nil check.
EternallySpeedy
#183911509Friday, February 19, 2016 12:02 AM GMT

Maybe the "if Mouse.Target ~= nil then, is supposed to be if (Mouse.Target ~= nil) then. ~EternallySpeedy~
cofunction
#183911575Friday, February 19, 2016 12:03 AM GMT

^ doesn't make a difference.
CrustyCitation5
#183911594Friday, February 19, 2016 12:03 AM GMT

That should not change anything
EternallySpeedy
#183911640Friday, February 19, 2016 12:04 AM GMT

Sorry, I'm a beginning scripter, so I don't know things. ~EternallySpeedy~
OppaGagnamSta
#183911705Friday, February 19, 2016 12:05 AM GMT

i had a similar issue where this same exact error would pop up even though i had a nil check the only thing i could think of that would cause this is if Mouse.Target changed before it got to Mouse.Target.ClassName and therefore the new target was probably nil which caused the error i fixed my error by setting mouse.Target to a variable, like target = mouse.Target and then doing if statements on the target variable because it won't change once you set it, unlike using mouse.Target which might change before the function ends
cofunction
#183911778Friday, February 19, 2016 12:06 AM GMT

All goods. @OP: Try this: if Mouse.Target and Mouse.Target.ClassName == "Part" then instead of: "if Mouse.Target ~= nil then if Mouse.Target.ClassName == "Part" then" I'm currently scripting something which involves mouse.Target and the code I suggested doesn't throw any errors.
Rocky28447
#183911862Friday, February 19, 2016 12:07 AM GMT

Tried it in studio and it works for me. choo choo
Rocky28447
#183911925Friday, February 19, 2016 12:08 AM GMT

also don't use "if Mouse.Target.ClassName == "Part" then" use if Mouse.Target:IsA("BasePart") then choo choo
CrustyCitation5
#183912094Friday, February 19, 2016 12:11 AM GMT

@Oppa I'll try that. @Advanced I already tried that. Error still throws. @Rocky Your script isn't working on the same level as mine. This is the base of a much larger script that works with a huge amount of server parts. I think Oppa's statement is right where it changes the Mouse.Target mid function
CrustyCitation5
#183912394Friday, February 19, 2016 12:16 AM GMT

No way that actually worked. Oppa thank you sir. I also combined what Advanced said to it. Shouldn't have a problem anymore. Thanks guys @Rocky Good suggestion, looks shorter. No idea why I didn't think about it.

    of     1