Hi there, I have this script that involves the mouse and checks if the mouse.Target’s parent finds a child called Humanoid. The issue is, is that if I were to click on something that doesn’t have a parent, it throws an error saying attempt to index nil with ‘Parent’. I’ve already tried adding else statements, but my main priority is to make it so that the error doesnt break my entire code. Is there a way to do this?
else
if dragging.Parent:FindFirstChild'Humanoid' then -- error is thrown
for i, v in ipairs(dragging.Parent:GetChildren()) do
if v:IsA'BasePart' then
v.CanCollide = v:GetAttribute('CanCollide')
v:SetAttribute('CanCollide',nil)
end
end
else
dragging.CanCollide = dragging:GetAttribute('CanCollide')
dragging:SetAttribute('CanCollide',nil)
end
end
also, “dragging” is the mouse.Target