Ok, first i call my function to return an object so i can clone it:
local newActualPad = closeByCheck(currentPly):Clone()
closeByCheck has to return me an object so i can clone it
local closeByCheck = function(ply)
local part
print("closeByCheck")
local signal
signal = ply:FindFirstChild("Right Leg").Touched:connect(function(otherPart)
print("Touched")
print(otherPart.Parent)
if otherPart.Parent == game.Workspace.Grid then
print("Part is grid")
if (ply.HumanoidRootPart.Position - otherPart.Position).magnitude < startRange then
print("Part is close")
part = otherPart
print(part.Name)
end
end
signal:disconnect()
end)
return part
end
When i run it, closeByCheck returns me nothing, and when the script is gonna clone, error, attempt to index a 'nil'

1 comment
It's most probably something with the 'if' at line 10, because if the if goes false then the part never gets defined, so it would return nil